With C language
Write the rand statement needed to assign x to a random integer from 1200 to 1500.
Here's complete program for you to assign x to a random integer from 1200 to 1500.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void printRandoms(int lower, int upper)
{
int num = (rand() % (upper - lower + 1)) + lower;
printf("%d ", num);
}
// Driver code
int main()
{
int lower = 1200, upper = 1500;
// Use current time as
// seed for random generator
srand(time(0));
printRandoms(lower, upper);
return 0;
}
Here's one Output :
If you are interested in one line statement, here it is for you :
int num = (rand() % (upper - lower + 1)) + lower;
Try running this code on your own system.
Like, if this helped :)
Get Answers For Free
Most questions answered within 1 hours.