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 CAD考试祝福语毕业简短
17 班级祝福语简短句子
18 亲人提车祝福语简短