• edited by
31,414 views
69 69 votes

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?

  1. An array of $50$ numbers

  2. An array of $100$ numbers

  3. An array of $500$ numbers

  4. A dynamically allocated array of $550$ numbers

5 Answers

Best answer
97 97 votes
As we our area of interest is only the $50$ numbers so take An array of $50$ numbers where $A[0]$ corresponds to $51...A[49]$ corresponds to $100$ then after reading an input just increment the counter in correct position as said above.

Correct Answer: $A$
• edited by
14 14 votes
Let read () be a function which returns the current value read from given  500 integers.

P[50] array of 50 elements ,where all elements is initialized to 0.

Program P()
{
For(i=1 to 500)
{
   x = read();
     if(x>50)
   {
     P[x%50]++; // here we can use P[x] ++ but  for that we would require array of size 100
   }
}
}

Therefore answer is A
• edited by
6 6 votes

Answer option (A) 

create an array of 50 elements where 0,1,2 index correspond to score 50,51,52 and so on  

see the below program 

2 2 votes
Given that

Program P reads in 500 integers in the range [0,100] representing the scores of 500 students.

then prints the frequency of each score above 50.It means frequency of scores 51 to 100(because score range is given [0,100]).

Here to store frequency of scores 51 to 100 (50 scores) we can use array of size 50.

we can use array of size 50 with starting index 51 to last index 100 and we can store frequency of each score 51 to 100. Here in array 51 to 100 represents indexes and corresponding values represent frequency of each score.

[example: a[51...100]

a[51]=7(assume 51 frequency is 7)

a[52]=8(assume 52 frequency is 8)

….

…..

…..

a[100]=20(assume 100 frequency is 20)   ]

 

Correct Answer : A
Answer:
Position:
Show:

Related questions

32 32 votes
3 answers 3 answers
15.4k
15.4k views
gatecse asked Sep 21, 2014
15,380 views
Let $f(x)$ be the continuous probability density function of a random variable $x$, the probability that $a < x \leq b$, is :$f(b-a)$$f(b) - f(a)$$\int\limits_a^b f(x) dx...
197 197 votes
9 answers 9 answers
78.1k
78.1k views
Kathleen asked Sep 22, 2014
78,059 views
A $5$ stage pipelined CPU has the following sequence of stages:IF – instruction fetch from instruction memoryRD – Instruction decode and register readEX – Execute: ALU op...
36 36 votes
5 answers 5 answers
16.3k
16.3k views
Kathleen asked Sep 22, 2014
16,328 views
Postorder traversal of a given binary search tree, $T$ produces the following sequence of keys$10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29$Which one of the following se...
45 45 votes
7 answers 7 answers
20.3k
20.3k views
Kathleen asked Sep 22, 2014
20,275 views
Consider a relation scheme $R = (A, B, C, D, E, H)$ on which the following functional dependencies hold: {$A \rightarrow B$, $BC \rightarrow D$, $E \rightarrow C$, $D \ri...