C++ program to add N numbers

In this article, we will learn the C++ program to add N numbers. For example, if the user sets n=5, the program will take 5 values from the user and add them.

Example: C++ program to add N numbers

//C++ program to add N numbers
#include<iostream>
using namespace std;
int main()
{
    int n, i, numbers, sum=0;
    cout<<"Enter N numbers: ";
    cin>>n;
    cout<<"Enter the values for "<<n<<" numbers:\n";
    for(i=0; i<n; i++)
    {
        cin>>numbers;
        sum = sum+numbers;
    }
    cout<<"\nSum will be: "<<sum<<endl;
    return 0;
}

Output

cpp program to add N numbers

Description and working of this program

  • The system asks the user to set n numbers for example n=5
  • The user enters the 5 values against each n number.
  • The program adds them and prints the sum on the screen

Recommended Articles

C++ program to print star patterns

C++ student grade program

Scroll to Top