Answer:
Check the explanation
Step-by-step explanation:
person.c
#include <stdio.h>
#include <stdlib.h>
typedef struct person
{
int age;
double height;
}Person;
void getAverage(Person persons[], int max)
{
int i, totAge=0;
double avgAge = 0.0, avgHeight = 0.0, ratio=0.0, totHeight = 0;
//calculate the Of age, height and the ratio Of to height(age/height):
for(i=0;i<max;i++)
{
totAge = totAge + persons[i].age;
totHeight = totHeight + persons[i].height;
}
//calculate the average
avgAge = totAge/max;
avgHeight = totHeight / max;
ratio = avgAge / avgHeight;
//output the results
printf("\\the average of age is: %lf", avgAge);
printf("\\the average of height is: %lf", avgHeight);
printf("\\the average ratio of age to height is: %lf", ratio);
}
int main()
{
//variables declaration
int id=0;
Person p[10];
//read data from keyboard, which are the age and the height of person
while(1)
{
printf("\\id: %d", id + 1);
printf("\\please enter the age: ");
scanf("%d", &p[id].age);
if(p[id].age < 0)
break;
printf("please enter the height: ");
scanf("%lf", &p[id].height);
id++;
}
//call getAverage function
getAverage(p, id);
return 0;
}
Kindly check the Screenshot and Output in the attached images below: