unsigned long long int
#include <iostream> using namespace std; int main(){ int input; cin >> input; // How many input for sum ? // just one variable that I use as input // then I just sum this variable via loop unsigned long long int sum = 0; for (int i =0; i < input; i++){ //loop for sum cin >> sum; sum+=sum; } cout << sum << endl; return 0; }
#include <iostream> using namespace std; int main(){ int input; cin >> input; // How many input for sum ? //two variables, one for input and one for sum of the input unsigned long long int sum = 0, in; for (int i =0; i < input; i++){ //loop for sum cin >> in; sum+=in; } cout << sum << endl; return 0; }
5 (How many input) 1000000001 1000000002 1000000003 1000000004 1000000005 (Actual input) Answer from code 1 = 2000000010 Correct answer (code 2) = 5000000015
cin >> sum; sum+=sum;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)