Combine the statements into a program that calculates and prints the sum of the integers from 1 to 10. . Use the while statement to loop through the calculation and increment statements. The loop should terminate when the value of x becomes 11.
```
// Calculate.cpp
// Calculate the sum of the integers from 1 to 10
#include
using namespace std;
int main() {
unsigned int sum{0};
unsigned int x{1};
while (x <= 10) { // while x is less than or equal to 10
sum += x; // add x to sum
++x; // increment x
}
cout << "The sum is: " << sum << endl;
}
```
The sum is: 55
Computer Science & Information Technology
You might also like to view...
LCD stands for ________ display
A) lumens and crystal B) liquid crystal C) laser compact D) liquid cathode
Computer Science & Information Technology
Which Blur filter simulates taking a picture of an object in motion?
A. Gaussian B. Smart C. Radial D. Motion
Computer Science & Information Technology