Pages

Thursday, February 2, 2017

Average of Array Elements

Find average of Array Elements.

Example: This program will find avg. of height of five students.



#include<stdio.h>
int main()
{
int i;
float avg_height,sum=0,height[5];
//Logic to read height of 5 students
printf("Enter height in foot.\n");
for(i=0; i<5; i++){
printf("Height of student%d:",i+1);
scanf("%f", &height[i]);
}
for(i=0; i<5; i++){
sum = sum + height[i];
}
avg_height = sum/5;
printf("Average height of 5 students = %.2f",avg_height);
return 0;
}

Output of program

Enter height in foot.
Height of student1:5.5
Height of student2:5.9
Height of student3:5.3
Height of student4:6.2
Height of student5:5.4
Average height of 5 students = 5.66

* * * * *

No comments:

Post a Comment