Computer Science, asked by arafath1108, 1 year ago

2. In the following program, what is the expected value of yourscore from options (i) to (iv)
given below. Justify your answer.
#include<iostream.h>
#include<stdlib.h>
void main()
{ randomize();
int score[] = { 15, 35, 34, 65, 27, 36), yourscore;
yourscore=score[3+random(3)];
cout<<yourscore<<endl; }
i) 27 ii) 15 iii) 34 iv) none of the above

Answers

Answered by Anonymous
0

random(3) will generate a number in the range 0 , 1 , 2 . So the value can be predicted but it won't be accurate .

So the array index of the variable yourscore is :

3 + random(3)

OPTION Verification

Now the first option is 27 .

27 = score [ 4 ] ;

So this is possible since 3 + random(3) may generate the output since random(3) may give 1 .

15 will never be generated as it is less than the index 3 and similarly 34 will never be generated as it is in the index of 2 .

So the answer is 27 .


Anonymous: thanks for brainliest .
Similar questions