// Calculate the sum of the integers from 1 to 10.
#include <iostream>
using namespace std;
int main()
{
unsigned int sum = 0; // stores sum of integers 1 to 10
unsigned int x = 1; // counter
while ( x <= 10 ) // loop 10 times
{
sum += x; // add x to sum
++x; // increment x
} // end while
cout << "The sum is: " << sum << endl;
} // end main






0 comments:
Post a Comment