C language has a built-in function to generate random numbers. In this program, we will use that function to generate a few random numbers.
Before you begin with the example, learn about C concepts. If you know the basics skip the step and continue with the example.
Problem Definition
The program uses the
Program Source Code
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, max, num, c;
printf("Enter Number of Random Numbers You Want:");
scanf("%d", &n);
printf("Enter Maximum value for the Random Numbers:");
scanf("%d", &max);
printf("%d random numbers from 0 to %d\n\n",n,max);
for(c = 1; c <= n; c++)
{
num = rand() % max + 1;
printf("%d\n",num);
}
system("PAUSE");
return 0;
}
Output
Enter Number of Random Numbers You Want: 10
Enter Maximum value for the Random Numbers: 1000
10 random numbers from 0 to 1000
42
468
335
501
170
725
479
359
963
465
Press any key to continue . . . _