C++ Program to Find Sum of N Numbers using Array
ADVERTISEMENTS
C++ program to find sum of N numbers using array. In this article, You will learn how to make c++ program to find sum of N numbers using array.
Source Code
// C++ Program to Find Sum of N Numbers using Array
#include <iostream>
using namespace std;
int main() {
int s, i, sum = 0;
// s - To store the size of the array
cout << "----Enter the size of the array----\n";
cin >> s;
int x[s];
// x - To store the array element to store the input numbers
cout << "\n\n----The sum of the " << s << " input numbers----\n\n";
for(i = 0; i < s; i++) {
cin >> x[i];
sum += x[i];
}
cout << "\n\nThe total sum is: " << sum;
return 0;
}
Output
----Enter the size of the array----
5
----The sum of the 5 input numbers----
24
243
23
4
25
The total sum is: 319