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

Discussion

Consider a program that reads 500 integers in the range of [0, 100] that represents the score of 500 students. Frequency of each score above 50 is then printed. For the program to store the frequencies the best way is

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

Answer: D

The best way is an array of 50 numbers.

Only the frequencies of scores above 50 are printed, and the possible scores above 50 in the range [0, 100] are 51, 52, ..., 100: exactly 50 values. One counter for each, indexed by score minus 51, needs an array of 50 numbers.

An array of 100 numbers wastes space on scores that are never reported, an array of 500 confuses the number of students with the number of possible scores, and a dynamic array of 550 has no basis at all.

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

Post your comment

Please log in or register to post a comment.