Write C++ Program to Find the Sum of Natural Numbers

This is the simple C++ program for beginners. The program will prompt user to enter a positive number and after this will display the sum of all natural numbers of that specific number.

Source Code 

#include <iostream>
using namespace std;

int main() {

int num, sum = 0;
cout << "Plz Enter a Positive Number ";
cin >> num;
for (int i = 1; i <= num; ++i) {
sum += i;
}
cout << "Sum = " << sum;
return 0;
}

Output of the Program


C++ Program to Find the Sum of Natural Numbers

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.

2 comments: