C++ Online Compiler
Example: Simple Array Sum Program in C++ using For loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Simple Array Sum Program in C++ using For loop #include <iostream> using namespace std; int main() { int s; cout << "Enter size of the array:\n"; cin >> s; int arr[s], sum=0; cout << "\nEnter the elements of the array:\n"; for (int i=0; i<s; i++) { cin >> arr[i]; sum += arr[i]; } cout << "\nSum = " << sum; return 0; }
8 1 3 5 7 8 9 23 56
Output
Clear
ADVERTISEMENTS