C-Library-Functions
- Which of these is a correct way to generate numbers between 0 to 1(inclusive) randomly?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
rand() % 2
- In the following C program everytime program is run different numbers are generated.
#include <stdio.h>
int main()
{
srand(time(NULL));
printf("%d\n", rand());
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
True
- In the below program everytime program is run different numbers are generated.
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("%d\n", rand());
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
False
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
srand(time(NULL));
printf("%d\n", rand());
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
An integer in the range 0 to RAND_MAX
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
printf("%d\n", srand(12000))
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Compilation Error
main.c: In function ‘main’:
main.c:4:24: warning: implicit declaration of function ‘srand’; did you mean ‘scanf’? [-Wimplicit-function-declaration]
printf("%d\n", srand(12000))
^~~~~
scanf
main.c:5:9: error: expected ‘;’ before ‘return’
return 0;
^~~~~~