Thursday, 28 June 2018

C program to find average of n element of array

/* average of n element of array */
# include <stdio.h>
void main ()
{
int a[20] , sum = 0 , avg , n , i ;
clrscr () ;
printf ("\n How many number you want to print:") ;
scanf ("%d", &n) ;
if ( n > 20 )
{
printf ("\n Invalid number:") ;
getch () ;
exit () ;
}
for ( i = 0 ; i < n ; i++ )
{
printf ("\n Enter a number:") ;
scanf ("%d", &a[i]) ;
}
for ( i =0 ; i < n ; i++ ) 
sum = sum + a[n] ;
avg = sum / n ;
printf ("\n avg = %d", avg) ;
getch () ;
}

  

No comments:

Post a Comment

Featured post

Program to find maximum of three number using user define function in C++

A function can be define by the user as per the requirement of the user or programmer . To implement a user define function , a programmer ...