#include <stdio.h>
#define SIZE 50
float avg_age(int [],int);
int main(void)
{
int i,b[SIZE],n;
float average;
printf("\n How many students are in the team:\n");
scanf("%d",&n);
printf("\n Enter the age of students in the team:\n");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
average=avg_age(b,n);
printf("\n the average age of students =%f", average);
return 0;
}
float avg_age(int a[], int n)
{
int j;
float sum=0.0;
for(j=0;j<n;j++)
sum=sum+a[j];
return sum/n;
}
How many students are in the team:
2
Enter the age of students in the team:
20
21
the average age of students =20.500000
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.