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

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.