Wednesday, 20 June 2012

how to calculate the sum of first 1000 integers



 This is the source code to calculate the sum of first 1000 integers
#include <iostream.h>
main()
{
        int sum, number;
        sum = 0;
        number = 1;
     while(number <= 1000)
{
      sum = sum + number;

      number = number + 1;
}
    cout << "The sum of first 1000 integers starting from 1 is " << sum;
getch();
 }
End

2 comments: