C Programming - Random Number Generation
Question 1
|
The function srand(unsigned)
Sets the seed for rand
| |
Doesn’t exist
| |
Is an error
| |
None of the mentioned
|
Question 2
|
Which is the best way to generate numbers between 0 to 99?
rand()-100
| |
rand()%100
| |
rand(100)
| |
srand(100)
|
Question 3
|
The correct way to generate numbers between minimum and maximum(inclusive) is _____________________.
minimum + (rand() % (maximum – minimum));
| |
minimum + (rand() % (maximum – minimum + 1));
| |
minimum * (rand() % (maximum – minimum))
| |
minimum – (rand() % (maximum+minimum));
|
Question 4
|
rand() and srand() functions are used
To find sqrt
| |
For and operations
| |
For or operations
| |
To generate random numbers
|
Question 5
|
What is the return type of rand() function?
short
| |
int
| |
long
| |
double
|
Question 6
|
Which of the following can be used for random number generation?
random()
| |
rnd()
| |
rndm()
| |
None of the mentioned
|
Question 7
|
Which of the following snippet will effectively generate random numbers?
rand();
| |
rand(10);
| |
rand(time(NULL));
| |
All of the mentioned
|
Question 8
|
Which among the following is correct function call for rand and random?
rand() and random();
| |
rand() and random(1);
| |
rand(1) and random(1);
| |
rand(1) and random();
|
Question 9
|
For the function call time(), what type of parameter is accepted?
int
| |
int *
| |
time_t
| |
time_t *
|
Question 10
|
What is the output of this C code?
Compile time error
| |
An integer between 0-1000
| |
An integer between 0-999 including 0 and 999.
| |
An integer between 0-1000 including 1000
|
Question 11
|
What is the output of this C code?
Compile time error
| |
An integer in the range 0 to RAND_MAX.
| |
A double in the range 0 to 1
| |
A float in the range 0 to 1.
|
Question 12
|
What is the output of this C code?
Compile time error
| |
An integer in the range 0 to 9000
| |
A float in the range 0 to 1
| |
A double in the range 0 to 9000
|
Question 13
|
What is the output of this C code?
Compile time error
| |
An integer in the range 0 to RAND_MAX.
| |
A double in the range 0 to 1
| |
A float in the range 0 to 1.
|
Question 14
|
In the below program everytime program is run different numbers are generated.
true
| |
false
| |
Depends on the platform
| |
Depends on the compiler
|
Question 15
|
In the below program everytime program is run different numbers are generated.
true
| |
false
| |
Depends on the platform
| |
Depends on the compiler
|
Question 16
|
Which of these is a correct way to generate numbers between 0 to 1(inclusive) randomly?
rand() / RAND_MAX
| |
rand() % 2
| |
rand(0, 1)
| |
None of the mentioned
|
Check Your Answers:
1. A
2. B
3. B
4. D
5. B
6. A
7. A
8. A
9. D
10. C
11. B
12. A
13. B
14. B
15. A
16. A
0 comments:
Post a Comment