codescracker


c++

C++ Program to Add n Numbers



« Previous Program Next Program »


Add n Numbers in C++

To add n numbers in C++ Programming, you have to ask to the user to enter the value of n (i.e., how many numbers he/she want to enter to all the numbers), then ask to enter n numbers to perform the addition of all the n numbers to display the result on the screen as shown here in the following program.

C++ Programming Code to Add n Numbers

Following C++ program first ask to the user to enter the value of n and then ask to enter the n Number to add them. This C++ program add all n numbers entered by the user.

C++ Programming Example Code:
/* C++ Program - Add n Numbers */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int i, n, sum=0, num;
	cout<<"How many number you want to enter and add them ?";
	cin>>n;
	cout<<"Enter "<<n<<" number :";
	for(i=0;i<n;i++)
	{
		cin>>num;
		sum=sum+num;
	}
	cout<<"Sum of all the "<<n<<" number is "<<sum;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program to add n numbers

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test