C++ Online Compiler
Example: C++ Program to Find Average of N Numbers using Array
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find Average of N Numbers using Array #include <iostream> using namespace std; int main() { int x, i; float avg = 0.00; // x - To store the number of elements // avg - To store the total average value // y - To store the total input numbers cout << "Enter the number of elements to calculate the average::\n"; cin >> x; float Num[x]; cout << "\nEnter " << x << " elements one by one\n"; for(i = 0; i < x; i++) { cin >> Num[i]; avg += Num[i]; } avg /= x; cout << "\nAverage of the entered input numbers is = " << avg; return 0; }
5 12 43 65 78 90
Output
Clear
ADVERTISEMENTS