Thursday, 21 June 2018

How to write program to find average of an array of 5 elements

/* Avg of an array */
# include <stdio.h>
void main ()
{
int a[5],i,avg ;
int sum = 0 ;
clrscr () ;
for ( i=o ; i<5 ; i++ )
{
printf ("\n Enter a number:") ;
scanf ("%d"< & a[i]) ;
}
for ( i=0 ; i<5 ; i++ )
sum = sum + a[i] ;
avg = sum / 5 ;
printf ("\n avg= %d", avg) ;
getch () ;
}


DRY RUN ;

sum =0 i=0 0<5
a[0] = 11
i=0 0<5 (TRUE)   i++ = 1
sum = sum + a[i]

similarly
for  i = 1,2,3,4  having true

for i = 5 ( 5<5 ) false

1 comment:

  1. It is actually a great and helpful piece of information. I am satisfied that you simply shared this helpful information with us. Please stay us informed like this. Thanks for sharing. Guest Posting Sites List 2018

    ReplyDelete

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 ...