-3
Someone can help create a C program that generates the value 0 or 1, once and store it in a variable.
I tried to do it but it didn’t turn out the way I’d hoped:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
float chuva()
{
int i;
float chuva;
for(i=0 ; i <= 1 ; i++)
{
chuva = ( 0 + rand()%1);
printf("chuva= %d: %d\n",i, rand());
if(chuva=1)
printf("Choveu\n");
else
printf("Nao choveu\n");
}
}
You have already asked this: https://answall.com/q/525221/5878
– Woss
put 2 in place of
%1
– Bernardo Lopes
See the function documentation
rand()
and also the table of arithmetic operators in C– Augusto Vasques
rand() % 1
takes the random value returned byrand
and returns the rest of the division by 1. But every whole number is divisible by 1, so the rest of the division by 1 is always zero. And then you add zero to that result, which changes nothing, that is, the result of0 + rand()%1
is always zero– hkotsubo