Help to add the loop
Can anyone help me when i run my loop display
Output
5
4
3
2
1
the sum is 6(the answer must be 15)
what is the code for a correct adding of the loop
what is the code that you tried. the following simple code accomplishes the purpose.
1 2 3 4 5 6 7
|
int sum = 0;
std::cout << "Output" << endl;
for (int i=5;i>0;i--) {
std::cout << i << endl;
sum += i;
}
std::cout << "the sum is " << sum;
|
thx
Topic archived. No new replies allowed.