C
Programming and Technical
Programming
Q. What is the code for picking a random number from fifty numbers and that fifty number set have 8 sets
Read Solution (Total 4)
-
- #include
#include
#include
int main()
{
int x;
srand(time(NULL));
x=rand()%51;
printf("%d",x);
}
rand() fumction is used to pick a random number and this no. is not same for every time
- 10 years agoHelpfull: Yes(0) No(1)
- what is the meanining of this line?
srand(time(NULL));
- 10 years agoHelpfull: Yes(0) No(0)
- srand(time(NULL)); It seeds the random number generator with the current system time.
The NULL means that the value (the time in seconds) isn't stored anywhere. - 10 years agoHelpfull: Yes(0) No(0)
- srand(any fixed value means..1,2,3....or any value).
i.e.
while(1)
{
srand(5);
r=rand()&51;
pf("%dn",r);
}
it means that infinite loop right, so each time it gives same value inbetween 1-50.
But
if u take srand(time(1)); every one second value will be change between 1-50.
u can take srand(getpid()); means every execution of ur program value will be change.
getpid()--> process id.
- 10 years agoHelpfull: Yes(0) No(0)
C Other Question