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