Home / Programs / Write a program in C that uses a function to find the average age of students of a class chosen for a junior quiz competition.
Programming Example

Write a program in C that uses a function to find the average age of students of a class chosen for a junior quiz competition.

👁 2,545 Views
💻 Practical Program
📘 Step by Step Learning
Write a program in C that uses a function to find the average age of students of a class chosen for a junior quiz competition.

Program Code

#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;
}
 

Output


 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
 

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.