C++ Online Compiler
Example: C++ Program to Find Average of N Numbers using While loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find Average of N Numbers using While loop #include <iostream> using namespace std; int main() { int x, i = 0; float avg = 0, y; // 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; cout << "Enter " << x << " elements one by one\n\n"; while (i < x) { cin >> y; avg += y; i++; } avg /= x; cout << "\nThe average of the entered input numbers is = " << avg; return 0; }
4 6462 62 5645 667
Output
Clear
ADVERTISEMENTS