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.
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
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.
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
Assembly Language Programming Write a complete assembly program that inputs a small signed integer n, whose...
Assembly Language Programming Write a complete assembly program that inputs a small signed integer n, whose value can fit within 8 bits, and outputs the value of the expression n2 – n + 6. (This is not C++ or Java. Has to be masm file)
Write the following in C: 2. An integer is said to be prime if it is...
Write the following in C: 2. An integer is said to be prime if it is divisible by only 1 and itself. Write a function called prime() that takes in one integer number, and returns 1 (true) if the number is prime and 0 (false) otherwise. Write a program to generate six random numbers between 1 to 100 and calls function prime() on each one to determine if it is prime or not.
Write a C++ program to do the following: Declare and assign values to int variables x,...
Write a C++ program to do the following: Declare and assign values to int variables x, y Declare an int variable z; and store the sum of x and y in it Declare a pointer called pz and point it in the heap direction (using new) Store the z value in the heap location using the pz pointer Print the content of the pz pointer Print the pointer (the address)
IN C LANGUAGE This program initially reads two integers from standard input: (1) an integer T...
IN C LANGUAGE This program initially reads two integers from standard input: (1) an integer T and (2) a positive integer N. It then reads N integers and counts the numbers that are greater than T and the numbers than are less than T. It then prints out these two counts. Example What is the threshold value? 7 How many values? 5 Enter 5 values: 6 7 9 9 8 3 values are greater than 7 1 values are less...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT