148k views
0 votes
Nummembers is read from input as the size of the vector. then, nummembers elements are read from input into the vector idlogs. use a loop to access each element in the vector and if the element is less than averagemembers, output the element followed by a space.

ex: if the input is 4 154 188 144 43, then the output is:

average: 132
numbers less than average: 43

1 Answer

2 votes

Final answer:

To solve this problem, you need to read the input values, calculate the average of the numbers in the vector, and output the numbers that are less than the average.

Step-by-step explanation:

To solve this problem, you need to follow these steps:

  1. Read the value of nummembers from the input.
  2. Create a vector called idlogs with a size of nummembers.
  3. Use a loop to read nummembers elements from the input and store them in idlogs.
  4. Calculate the average of the numbers in idlogs by adding them up and dividing by the size of idlogs.
  5. Initialize a variable called count to 0.
  6. Use another loop to access each element in idlogs.
  7. Inside the loop, check if the element is less than the average.
  8. If it is, output the element followed by a space and increment count by 1.

Finally, output the average and the count of numbers less than the average.

For example, if the input is: 4 154 188 144 43, the output would be: Average: 132 and Numbers less than average: 43.

User Marco Cutecchia
by
8.1k points