In C languange please A company stores the information about
In C languange please
A company stores the information about each employee using the following structure. #define NAME_MAX 25 typedef struct employee {char name [NAME_MAX]; int age; float salary;} EmpRec; You are required to write the function employee_stat with the following header: float employee_stat (EmpRec company [], int nemp, int *age_range) Here, the parameter company[] represents an array of records, with one record (of type EmpRec) corresponding to each employee. The parameter nemp represents the number of employees. (Thus, the indices for the company[] array vary from 0 to nemp-1.) Assume that the value of nemp is at least 1. At the end of the function, the reference parameter *age_range should have the number of employees whose age is at least 21 and at most 30. Further, the return value of the function must be the average salary of all the employees. You need to show the code only for the above function. There is no need to include comments and you may use magic numbers in your code.Solution
Here is the C code for the required function:
#include <stdio.h>
#define NAME_MAX 25
typedef struct employee
{
char name[NAME_MAX];
int age;
float salary;
}EmpRec;
float employee_stat(EmpRec company[], int nemp, int *age_range)
{
*age_range = 0;
float sum = 0;
for(int i = 0; i < nemp; i++)
{
if(company[i].age >= 21 && company[i].age <= 30)
(*age_range)++;
sum += company[i].salary;
}
return sum / nemp;
}
If you need any refinements, just get back to me.
