C Online Compiler
Example: C program to find average of N numbers using Array and Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to find average of N numbers using Array and Function #include <stdio.h> // This function will find the average of N numbers void FindAverage(int size) { float avg = 0; // To store the total average value float numbers[size]; // To store the values into Array printf("\nEnter %d elements one by one::\n", size); for(int i = 0; i < size; i++) { scanf("%f", &numbers[i]); avg += numbers[i]; } avg /= size; printf("\nThe average of the entered input numbers is = %f\n", avg); } // It's the driver function int main() { int x; // To store the number of elements printf("Enter the number of elements to calculate average::\n"); scanf("%d", &x); FindAverage(x); return 0; }
5 23 54 56 98 12
Output
Clear
ADVERTISEMENTS