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.

C Programming Language / Function in C Language

2524

Program:

#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

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.