Sunday, 5 October 2014

Calculate the sum of the integers from 1 to 10.

Leave a Comment












#include <iostream>
using namespace std;
void main() // starting point
{
      int sum, x;
      x = 1;
      sum = 0;
      while( x <= 10 )//loop for repeating 10 times
      {
             sum += x;
             ++x;
      }
      cout << "The sum is: " << sum << endl;// output point
      system("pause");
}

Output

If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: