I was writing a very basic C++ code. I am takin 2 lines of inputs
First line -> number of integers: 1<N<10
Second line -> long integers separated by whitespace: 0< ar[i] < 10^10
Example input:
5
1000000001 1000000002 1000000003 1000000004 1000000005
My function should return the resultant value. Here it is:
long aVeryBigSum(vector<long> ar,int ar_count) {
long result;
for (int i = 0; i < ar_count; i++) {
result = result + ar[i];
cout << to_string(result) + "\n";
}
return result;
}
Output:
5000000015
It works fine with this way; however, when I comment out the "cout" line, it returns something gibberish:
140741662329871
I don't understand why that happens. I'd appreciate if someone could. Thanks in advance.