x

C program to generate random numbers

C program to generate random numbers:


#include <stdio.h>

#include <stdlib.h>

int main()

{

int i, n;

printf(“Five random numbers between 1 and 100000\n”);

for (i = 1; i <= 5; i++)

{

n = rand()%100000 + 1;


printf(“%d\n”, n);

}

return 0;

}

 

Output:

Five random numbers between 1 and 100000

89384

30887

92778

36916

47794

 

Note: Above random numbers will be different every time we execute this C program.



Like it? Please Spread the word!