Calculate the Sum of first 1000 integers in C++ Program

Today we make program in C++ language for calculating the sum of first 1000 integers using while loop. And print the result.C++ Program to Display the Sum of the Digits of a given Number. * C++ program to Display the Sum of the digits of a given Number.

C++ Program to Calculate Sum of Natural Numbers

#include <iostream>
#include <conio.h>
using namespace std;
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();
}

Output of Program

Enter a positive integer: 50
Sum = 1275