Question

With C language Write the rand statement needed to assign x to a random integer from...

With C language

Write the rand statement needed to assign x to a random integer from 1200 to 1500.

Homework Answers

Answer #1

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 :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using the Java language program Demonstrate multiway if statement 1.1 Generate an integer random number from...
Using the Java language program Demonstrate multiway if statement 1.1 Generate an integer random number from -5 to 5.(Hint: Use Math.random()) 1.2 Write a multiway if statement that will display whether the number is positive, negative or zero. 1.3 Be sure to test your code with all three cases
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
[C++ Language] Write a function to find out the average of an integer array and return...
[C++ Language] Write a function to find out the average of an integer array and return to the main function.
(C++)Randomized Quicksort: Write C++ codes for randomized quicksort. You may need rand() to generate random numbers....
(C++)Randomized Quicksort: Write C++ codes for randomized quicksort. You may need rand() to generate random numbers. Run the randomized quicksort 5 times for input array A = {1, 2, 3, …, 99, 100} and report the 5 running times.
Assume that an integer value is already stored in x. Write a conditional statement that will...
Assume that an integer value is already stored in x. Write a conditional statement that will print "Yes" if x is not an exact multiple of 3 and "No" otherwise. Proper indentation is required for full marks.
For C++: a) Write a function is_prime that takes a positive integer X and returns 1...
For C++: a) Write a function is_prime that takes a positive integer X and returns 1 if X is a prime number, or 1 if X is not a prime number. b) write a program that takes a positive integer N and prints all prime numbers from 2 to N by calling your function is_prime from part a.
In C programming language write a function that takes an integer n as input and prints...
In C programming language write a function that takes an integer n as input and prints the following pattern on the screen: 1 (n times) 2 (n-1 times) .n (1 time) For example, if n was 5, the function should print 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
Write a statement which assigns all the odd integer values between 0 and 10 (in order)...
Write a statement which assigns all the odd integer values between 0 and 10 (in order) to the variable named odds. Python Language
All in C language... Write a complete program that declares an integer variable, reads a value...
All in C language... Write a complete program that declares an integer variable, reads a value from the keyboard into that variable, and writes to standard output the variable's value, twice the value, and the square of the value, separated by spaces. Besides the numbers, nothing else should be written to standard output except for spaces separating the values. I got this... and it's wrong #include<stdio.h> int main() { int num; scanf("%d", &num); printf("%d %d %d",num,2*num,num*num); return 0; }
Create a C++ program that generates a random number from 1 to 100 using the rand()...
Create a C++ program that generates a random number from 1 to 100 using the rand() function. Give the user a total 5 chances to guess the number. Stop the program and indicate the user guessed the correct number and should be applauded. Also, please find out which guess was the closest to the actual number. For example, if the rand() produces 57 and the user guessed 10, 80, 52, 33 and 44 in their respective turns then print out...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT