C++ Program to Find Sum of Natural Numbers

Advertisements

Prev Tutorial Next Tutorial

Find Sum of Natural Numbers Program in C++

Natural Numbers are counting numbers, that is 1, 2, 3, 4, 5, 6, 7... etc. Remember, zero and negative numbers are not part of natural numbers. In this program, we will take a positive number N as input from user and find the sum of all natural numbers between 1 to N(including 1 and N).

Example

Enter the number of integers to add: 5
1 2 3 4 5 
SUM = 15

To understand below example, you have must knowledge of following C++ programming topics; for looping statements we need know For Loop in C++ and Cout and Cin in C++.

C++ program to find sum of numbers between 1 to N

#include<iostream.h>
#include<conio.h>

void main()
{
    int N=0, num, i, sum=0;
    clrscr();  
    cout<<"Enter the Number of Integers to Add: ";
    cin >> N;
      
    cout<<"Enter "<<N<<" Numbers: ";
    for(i= 0; i< N; i++){
        cin>>num;
        sum = sum + num;
    }
    cout<<"Sum is: "<<sum;

    getch();
}

Output

Enter the Number of Integers to Add: 5
3
5
6
1
20
Enter 5 Numbers: 35
find sum of natural number in c++
Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements