Program – Find the average of n numbers
#include <stdio.h>
void main ()
{
int n, i;
float list [100], avg;
float average (float [], int);
/*function declaration*/
clrscr ();
printf (“\nenter the number of numbers:”)
scanf (“%d”, &n);
printf (“\nenter the numbers\n”);
for (i = 0; i<n; i ++)
scanf (“%f”, &list[i]);
avg = average (list, n);
printf (“\naverage = %9.2f”, avg);
getch ();
}
float average (float x [], int a)
{
int p;
float sum = 0.0, aver;
for (p=0;p<a;p++
sum = sum + x [p];
aver = sum/(float)a;
return (aver);
}
Output
enter the number of numbers: 5
enter the numbers
70
80
78
65
97
average = 78.00
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc