Answer:
The answer to the question is explained below
Step-by-step explanation:
#include <stdlib.h>
#include <stdio.h>
#define MAXNUM 100
typedef struct person
{
int age;
double height;
}
person;
int getData(person people[], int max)
{
printf("Enter your age(or -1 to quit):");
int n = 0;
scanf("%d", &people[n].age);
while (people[n].age>0)
{
if(n == MAXNUM)
{
printf("You have reached the maximum limit");
return n;
}
printf("Enter your height:");
scanf("%lf", &people[n++].height);
printf("Enter your age(or -1 to quit):");
scanf("%d", &people[n].age);
}
return n;
}
void getAverages(person people[], double *averageAge, double * averageHeight, double *averageRatio, int numPeople)
{
*averageAge = 0;
*averageHeight = 0;
for(int i = 0; i <numPeople; i++)
{
*averageAge += people[i].age;
*averageHeight += people[i].height;
}
*averageAge /= numPeople;
*averageHeight /= numPeople;
*averageRatio = *averageAge / *averageHeight;
}
void printAverages(double averageAge, double averageHeight, double averageRatio)
{
int age;
double height;
printf("Result:\\");
printf("Average age is %.2lf\\", averageAge);
printf("Average height is %.2lf\\", averageHeight);
printf("The average age/height ratio is %.2lf\\", averageRatio);
}
void main(void)
{
person people[MAXNUM];
int numPeople;
double averageAge, averageHeight, averageRatio;
numPeople = getData(people, MAXNUM);
if (numPeople == 0);
getAverages(people, &averageAge, &averageHeight, &averageRatio, numPeople);
printAverages(averageAge, averageHeight, averageRatio);
}