How to Find Sum of Natural Numbers Using C++

[2379 views]




In this tutorial we will learn how can we Find Sum of Natural Numbers using C++ program. The concept of the program is that the user first need to input the range of number he wants to add. Then the for loop runs and takes the input as much as the range and starts to add the numbers one by one using the for loop. Then it prints the result outside of the for loop.

How to Find Sum of Natural Numbers Using C++

C++ Program to Find Sum of Natural Numbers

#include<iostream.h> #include<conio.h> void main() { int N=0, num, i, sum=0; clrscr(); cout<<"Enter the range of number 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 range of number to Add: 5 3 5 6 1 20 Enter 5 Numbers: 35
                 






Comments










Search Anything:

Sponsored Deals ends in






Search Tags

    C++ pseudocode for sum of natural numbers

    Sum of Natural Numbers program in C++