I know this question asked many times but I am facing different problem in my code, I try to calculate sum of long integers range between 2-15.
Code:
long array[20];
long NUMBERS;
cout << "How many numbers ? : ";
cin >> NUMBERS;
long sum=0;
for (int i = 0; i < NUMBERS;i++){
cout << "Input number " << (i+1) << " : ";
cin >> array[i];
}
cout << "Calculate Sum" << endl;
for (int i = 0; i < NUMBERS;i++){
sum = sum + array[i];
}
cout << "Sum is : " << sum << endl;
When I input these three numbers.
- 1234567
- 123456
- 12345
Output:
Sum is : 1370368
but actual answer is : 3703627.
I try these solutions summing-large-numbers and sum-of-alternate-elements-of-integer-array but still not get right solution, also how we can solve this problem if user input different number with different ranges.