A Very Big Sum C++ Program
A very big sum c++ program.
In this article, you will learn how to make a very big sum c++ program.
Example
Enter the size of array::
6
1000010000010001 1000010000010002 1000010000010003 1000010000010004 1000010000010005 1000010000010006
Big Sum = 6000060000060021
You should have knowledge of the following topics in c++ programming to understand these programs:
- C++
main()
function - C++
while
loop - C++
for
loop - C++ Array
Source Code
// A Very Big Sum C++ Program
#include <iostream>
using namespace std;
int main() {
int s = 0;
cout << "Enter the size of array::\n";
cin >> s;
long arr[s], sum=0;
int i=0;
while (i<s) {
cin >> arr[i];
sum += arr[i];
i++;
}
// It will return the final output
cout << "\nBig Sum = " << sum << endl;
return 0;
}
Output
Enter the size of array::
6
1000010000010001 1000010000010002 1000010000010003 1000010000010004 1000010000010005 1000010000010006
Big Sum = 6000060000060021
Explanation
In this given program we have taken the inputs size of the array 6
and the array's elements 1000010000010001, 1000010000010002, 1000010000010003, 1000010000010004, 1000010000010005, 1000010000010006
. Then we make a sum of each element of the array.
After the whole calculation above program will return the 6000060000060021
output of the program.
A Very Big Sum C++ Program using For loop
// A Very Big Sum C++ Program using For loop
#include <iostream>
using namespace std;
int main() {
int s = 0;
cout << "Enter the size of array::\n";
cin >> s;
long arr[s], sum=0;
for (int i=0; i<s; i++) {
cin >> arr[i];
sum += arr[i];
}
// It will return the final output
cout << "\nBig Sum = " << sum << endl;
return 0;
}