Mega Code Archive
Calculate the sum of the integers from 1 to 10 using while loop
#include
using std::cout;
using std::endl;
int main()
{
int sum;
int x;
x = 1;
sum = 0;
while ( x <= 10 )
{
sum += x;
x++;
}
cout << "The sum is: " << sum << endl;
return 0;
}
The sum is: 55