0

Please tell how does each line get executed in it

int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; return 0;

3rd Oct 2018, 12:07 PM
Shadil saifi
Shadil saifi - avatar
1 ответ
+ 6
You declare 3 integers, 'num' (which is equal 1), 'number' and 'total' (which is equal 0). In loop 'while' you ask for input and add it to total, then increase 'num' (it's used as counter for loop, it executes 5 times). Finally you output value of variable 'total'.
3rd Oct 2018, 12:44 PM
Aleksander Szczepura
Aleksander Szczepura - avatar