Machine-translated by Google. Questions are authored in English.
Top

Discussion

A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies? 

  • A.An array of 50 numbers
  • B.An array of 100 numbers
  • C.An array of 500 numbers
  • D.A dynamically allocated array of 550 numbers

Answer: A

Correct answer: An array of 50 numbers

Only scores above 50 are to be reported, and the scores run from 0 to 100. That leaves the 50 values 51, 52, …, 100, so an array of 50 counters is enough - score \(s\) increments the cell at index \(s - 51\). Arrays of 100, 500 or 550 would work but waste space; the question asks for the best choice.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.