C Online Compiler
Example: C program to find average of N numbers using While loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to find average of N numbers using While loop #include <stdio.h> int main() { int x, i = 0; float avg = 0, y; // x - To store number of elements // avg - To store total average value // y - To store total input numbers printf("Enter the number of elements to calculate average::\n"); scanf("%d", &x); printf("Enter %d elements one by one\n\n", x); while (i < x) { scanf("%f", &y); avg += y; i++; } avg /= x; printf("\nThe average of the entered input numbers is = %f", avg); return 0; }
4 646 642 656 435
Output
Clear
ADVERTISEMENTS