C ++程序添加几个大数
假设我们有一个包含一些大数字的数组nums。大数字在范围内(-2^31到2^31-1)。我们必须找到这些数字的总和。
因此,如果输入类似于nums=[5000000003,3000000005,8000000007,2000000009,7000000011],那么输出将是25000000035。
示例
让我们看下面的实现来更好地理解
#include <iostream>
#include <vector>
using namespace std;
long long int solve(vector<long long int> nums){
long long int x = 0;
for(int i=0; i<nums.size(); i++){
x = x + nums[i];
}
return x;
}
int main(){
vector<long long int> nums = {5000000003, 3000000005, 8000000007, 2000000009, 7000000011};
cout << solve(nums);
}输入
{5000000003, 3000000005, 8000000007, 2000000009, 7000000011}输出结果25000000035
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短