How to Generate Random Numbers in C using rand() and srand() Function
Get Certified in C Programming and Take Your Skills to the Next Level
Program 1
#include<stdio.h>
#include<conio.h>
#include<time.h>
int main()
{
int n,i,l,u;
system("cls");
srand(time(NULL));
printf("Enter lower value of Random Number");
scanf("%d",&l);
printf("Enter upper value of Random Number");
scanf("%d",&u);
for(i=1;i<=5;i++)
{
n=(rand() %(u-l+1)) + l;
printf("%5d",n);
}
return 0;
}
We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

