Q:

We can rewrite this program using a for loop to sum the numbers from 1 through 10 as follows

0

We can rewrite this program using a for loop to sum the numbers from 1 through 10 as follows.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
int main()
{
int sum = 0;
// sum values from 1 through 10 inclusive
for (int val = 1; val <= 10; ++val)
sum += val; // equivalent to sum = sum + val
std::cout << "Sum of 1 to 10 inclusive is "
<< sum << std::endl;
return 0;
}

 

Output:

Sum of 1 to 10 inclusive is 55

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now