Computer Science, asked by skumaaranmol762, 11 months ago

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

Answers

Answered by Anonymous
0

Answer:

Explanation:

An array of size 50 will be the best option to store number of students for each score. The frequencies of scores above 50 need to be stored. The scores below 50 and to index the scores above 50 can be ignored, and 50 can be subtracted from the score value. Thus -

Creating an array of integers with size=101, we will store the frequency of the numbers against the indexes of the array.

main()

[

 int arr[101], i, temp;

for(i=0; i<101; i++)

arr[i]=0;

for(i=0; i<500; i++)

[

scanf(“%d”,& temp);

arr[temp]++;

]

for(i=0; i<102; i++)

if(arr[i] > 50)

printf(“ frequency of %d is %d”, i,arr[i]);

]

Thus, arr[i] will store the frequency of number i.

Similar questions