0
Q:

how to genrate a random number in C

#include <time.h>
#include <stdlib.h>

srand(time(NULL));   // Initialization, should only be called once.
int r = rand();      // Returns a pseudo-random integer between 0 and RAND_MAX.
3
srand(time(NULL));
  int r = rand();
0
#include <stdio.h>

int main(){
    int i = 0;
    while(i < 50)
    {
        int num;
        num = rand(); //this function generates the random number
        printf("%i\n", num);
        i++;
    }

return 0;
}
0

New to Communities?

Join the community