C++ Online Compiler
Example: C++ Program to Find Sum of N Numbers using Array
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// 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; }
5 24 243 23 4 25
Output
Clear
ADVERTISEMENTS