C Programming
Computer Programming

Program in C to find the mean of n number using pointer



Write a Program in c to find the mean of n number using pointer

\* C Program to to find the mean of n number using pointer *\

# include < stdio.h >
int   main( )
{

int   a[20], n, i, sum=0  ;
float   mean  ;
int   *ptr  ;
printf(" How many Numner you want to enter: ") ;
scanf("%d ", & n) ;
printf("\n Enter the number : \n") ;

for (i = 0; i < n ; i++   )
{

scanf("%d ", & a[i]) ;
ptr++  ;

}
ptr = & a[0]  ;
printf(" \n Element in array are :\n ") ;
for (i = 0; i < n ; i++   )
{

printf("\t %d ", ( *ptr )) ;
sum = sum + *ptr  ;
ptr++  ;

}
mean = sum / n  ;
printf("\n Mean of %d Numbers are : %f ", n, mean) ;
return ( 0 );

}

Output of Program :

Output of Program in C to find the mean of n number using pointer