Accept n number from user, store these number into an array and calculate the average of n number

How to write a C Program to accept n number from user, store these number into an array and calculate the average of n number in C Programming Language ?


Solution:
/*write a c progarm to accept n number from user, store
these number into an array and calculate the average of n
number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,sum=0;
float avg;
clrscr();
printf("\nenter how many number :");
scanf("%d",&n);
printf("\nenter the element :\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
avg=sum/n;
printf("\nthe average is :%f",avg);
getch();
}
/*
enter how many number :5                                                    
                                                                           
enter the element :                                                        
9                                                                          
8                                                                          
7                                                                          
4                                                                          
5                                                                          
                                                                           
the average is :6.000000                                                    
*/


Learn More :