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 Volume of given box in java

class volume { public static void main (String args []) { int l=5,b=6,h=10; int volume; volume=l*b*h; System.out.println (" vol...