1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sophie [7]
4 years ago
13

Task:create a struct that looks like:typedef struct person{ int age; double height;} Person;Create an array of Persons. Read dat

a for multiple persons from the keyboard. Stop when a negative age is found. Then find the average height, the average age, and the average ratio of age to height(age/height

Computers and Technology
1 answer:
Amiraneli [1.4K]4 years ago
6 0

Answer:

Check the explanation

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("\nthe average of age is: %lf", avgAge);

  printf("\nthe average of height is: %lf", avgHeight);

  printf("\nthe 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("\nid: %d", id + 1);

      printf("\nplease 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:

You might be interested in
Is greedy algorithm non deterministic by nature?
Flura [38]

Answer: Yes

Explanation: Greedy algorithm is the algorithm that gives the solution to the problem on the basis of the piece by piece or step by step architecture.  the next step of the solution is based on the aim of solving problem optimally.But the steps chosen can be correct or incorrect.

Non-deterministic nature is the feature that determines that the  steps that is being chosen is not the most optimal one and no high surety is present.Thus, this nature is present in the greedy algorithm and it has non-deterministic nature.

7 0
3 years ago
What does c++ programming mean?
cestrela7 [59]

Answer:

It's an internal joke to say the language is basically C with some extra stuff (like classes)

the "++" is short for

C += 1 or

C = C + 1 which is a common calculation among programmers so they named it C++ to be a more commercial and attractive name than "C with classes"

Explanation:

8 0
3 years ago
Anisha was learning ‘for’ and ‘while’ loop. Help her understand why for and while loops are called entry controlled loops.
Andrew [12]

Entry controlled loop - <u>The loop which has a condition check at the entrance of the loop, the loop executes only and only if the condition is satisfied is called as entry control loop.</u>

So, for and while loops are its examples.

6 0
3 years ago
HELP!!!<br> THIS HAPPENS EVERY TIME
Lelu [443]
Idek but hope u figure it out!
4 0
3 years ago
Read 2 more answers
Consider the partially-filled array named a. What does the following loop do? (cin is a Scanner object)int[] a = {1, 3, 7, 0, 0,
boyakko [2]

Answer:

Option 1: May crash at runtime because it can input more elements than the array can hold

Explanation:

Given the code as follows:

  1.        int[] a = {1, 3, 7, 0, 0, 0};
  2.        int size = 3, capacity = 6;
  3.        int value = cin.nextInt();
  4.        while (value > 0)
  5.        {
  6.            a[size] = value;
  7.            size++;
  8.            value = cin.nextInt();
  9.        }

From the code above, we know the <em>a</em> is an array with six elements (Line 1). Since the array has been initialized with six elements, the capacity of the array cannot be altered in later stage.

However, a while loop is created to keep prompting for user input an integer and overwrite the value in the array started from index 3 (Line 4- 9). In every round of loop, the index is incremented by 1 (Line 7). If the user input for variable <em>value</em> is always above zero, the while loop will persist.  This may reach a point where the index value is out of bound and crash the program. Please note the maximum index value for the array is supposedly be 5.  

8 0
3 years ago
Other questions:
  • Which device or software application detects errors in system configurations?
    8·1 answer
  • The main parts of a lever are the....
    6·2 answers
  • Why are the READ and DATA statements used<br>together?​
    10·1 answer
  • What should you do if you forget your root password for MySQL?
    13·1 answer
  • Consider the following method, inCommon, which takes two Integer ArrayList parameters. The method returns true if the same integ
    15·1 answer
  • Ns.office.com/Pages/ResponsePage.aspx?id=bd8
    9·2 answers
  • #done with school already
    14·1 answer
  • Why do meteorologists use data such as temperature, wind speed, and air
    9·1 answer
  • You are given a graph G = (V, E) with positive edge weights, and a minimum spanning tree T = (V, E’) with respect to these weigh
    14·1 answer
  • Can someone pelaseee help
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!