Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion
Computer Science
URGENT!!-Ans req within 2day nite please...
None
URGENT!!-Ans req within 2day nite please...
pls tell me how randomize() works
Ex..
#include<stdlib.h>
#include<iostream.h>
void main()
{
randomize();
int m[]={99,92,94,96,93,95}, M;
M=m[1+random(2)];
cout<<M;
}
Ex..
#include<stdlib.h>
#include<iostream.h>
void main()
{
randomize();
int m[]={99,92,94,96,93,95}, M;
M=m[1+random(2)];
cout<<M;
}
1. 99
2. 94
3. 96
4. NONE
Pls tell whether my reason is correct!
Random(2)- will return either return 0,1,2(doubt1-is 2 included)
So possible values inside[] are 1,2,3
so the possibilities are 99,92,94..
Which is correct??
Random(2)- will return either return 0,1,2(doubt1-is 2 included)
So possible values inside[] are 1,2,3
so the possibilities are 99,92,94..
Which is correct??












random(2) generates 2 numbers starting from 0...therefore 0 and 1 is generated.now 1 is added to it so it becomes 1 or 2..in the array the location corresponds to the elements 92 and 94 ...therefore option 2 is right