Program to Add n numbers in C++.

This C++ program add all ‘n’ numbers entered by the user This program first ask to the user to enter the value of ‘n ‘ and then ask to enter the ‘n’ Number to add them then it Display the result on Screen.

 

 

Let’s write a program which print sum of n numbers in C++.

 

 

Step 1: Let’s open turboC++ and write the following Code .

 

 

//Code:

 

 

#include<iostream.h>

#include<conio.h>

void main()

{

long int   i,n,a,sum=0;

//Clear Screen

clrscr();

cout<<”How many numbers do you want to Add ?\n”;

cin>>n;

cout<<”enter <<”n”<<numbers:\n”;

for(i=o;i<n;i++)

{

cin>>a;
sum=sum+a;

}

cout<<”sum:=”<<sum;

getch();

}

 

 

Step 2: Run the Program and see Output.

 

 

Output:

 

 

output

 

Happy Coding.

 

 

 

Tags: , , , ,

Comments are closed.