I am trying to manipulate srand
so that srand returns a decimal number by division. But it's not working. My Code doesn't return a decimal number even though precedence rules should prioritize brackets before division.
#include <stdio.h>
#include <math.h>
int main(void) {
double save;
srand(time(NULL));
save = (rand() % 100)/ 10;
printf("%f", save);
return 0;
}
However this code works fine, but I'm not happy with the solution.
#include <stdio.h>
#include <math.h>
int main(void) {
double save;
srand(time(NULL));
save = rand() % 100;
save = save / 10;
printf("%f", save);
return 0;
}
Can anyone explain this and give a better solution?