Question

In: Computer Science

Write a C++ program to generate two random numbers (Rnd1 and Rnd2). These two numbers should...

Write a C++ program to generate two random numbers (Rnd1 and Rnd2). These two numbers should be within a range [100, 500]. If Rnd1 greater than or equals to Rnd2, print out the result of (Rnd1-Rnd2). Otherwise, print out the result of (Rnd2-Rnd1). In all cases, print Rnd1, Rnd2, and the results of subtractions in suitable messages.

Solutions

Expert Solution

#include <iostream>
#include <stdlib.h>    
#include<time.h>
using namespace std;

int main()

{
    srand (time(NULL));//initializing the random seed(means, to change the numbers in every run)
   int Rnd1 = rand() % 500 + 100;//generate random number1 in range [100,500]
   int Rnd2 = rand() % 500 + 100;//generate random number2 in range [100,500]
   
   
   
   cout<<"Random Number 1 : "<<Rnd1<<"\nRandom Number 2 : "<<Rnd2<<"\n";
   
   if(Rnd1>=Rnd2)
   {
       cout<<Rnd1 <<" is greater and the difference is : "<<Rnd1-Rnd2;
       
   }
   else
   {
       cout<<Rnd2 <<" is greater and the difference is : "<<Rnd2-Rnd1;
   }
   

    return 0;
}

output


Related Solutions

For this problem, you will write a program using two queues. Generate n random numbers between...
For this problem, you will write a program using two queues. Generate n random numbers between 10 and 100 (both inclusive), where n>9. The value of n should be taken as input from the user and n should be >9. The numbers could be duplicated. Enqueue all these numbers to the first queue. The objective is to find the numbers whose sum of digits is odd and enqueue them to the second queue. The remaining numbers (whose sum of digits...
Write a program to simulate a calculator. Generate two random numbers (between 1-15) and an ask...
Write a program to simulate a calculator. Generate two random numbers (between 1-15) and an ask the user for an arithmetic operator. Using a switch statement, your program has to perform the arithmetic operation on those two operands depending on what operator the user entered. Ask the user if he/she wants to repeat the calculations and if the answer is yes or YES, keep repeating. If the answer is something else, then stop after the first calculation. c++
Write a Java program to generate random numbers in the following range a. 1 <=n <=...
Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 JAVA PROGRAMMING
For this assignment, write a program that will generate three randomly sized sets of random numbers...
For this assignment, write a program that will generate three randomly sized sets of random numbers using DEV C++ To use the random number generator, first add a #include statement for the cstdlib library to the top of the program: #include <cstdlib> Next, initialize the random number generator. This is done by calling the srand function and passing in an integer value (known as a seed value). This should only be done ONE time and it MUST be done before...
Write C++ program (submit the .cpp,.h, .sln and .vcxproj files) Problem 1. Generate 100 random numbers...
Write C++ program (submit the .cpp,.h, .sln and .vcxproj files) Problem 1. Generate 100 random numbers of the values 1-20 in an input.txt. Now create a binary search tree using the numbers of the sequence. The tree set should not have any nodes with same values and all repeated numbers of the random sequence must be stored in the node as a counter variable. For example, if there are five 20s’ in the random sequence then the tree node having...
java please 1. Write a Java program to generate random numbers in the following range a....
java please 1. Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 2. Write statements that assign random integers to the variable n in the following ranges: a) 1 ≤ n ≤ 2 b) 1 ≤ n ≤ 100 c) 0 ≤ n ≤ 9 d) 1000 ≤...
write c program to generate 6 numbers to simulate rolling of a dice . use while...
write c program to generate 6 numbers to simulate rolling of a dice . use while loop to run 100 and 10000 times. print out how many times it generates 1, 2,3,4,5,6.
Write a function that will generate an array of random numbers. It needs to:
DO IN C++Write a function that will generate an array of random numbers. It needs to:Take 3 integers as parameters-The first is the minimum value-the second is the maximum value-the third is the size of the new array-create a dynamically allocated array of the correct size-generate a random number (between min and max) for each element in the array-return a pointer to the arrayCreate a main() function that tests the above function and displays the values in the random array.
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a program to produce an array of integer random numbers. Your program should find out...
Write a program to produce an array of integer random numbers. Your program should find out from the user how many numbers to store. It should then generate and store that many random integers (the random numbers must be between 1 and 999 inclusive). The program should then determine the smallest number, the largest number, and the average of all the numbers stored in the array. Finally, it should print out all the numbers on the screen, five numbers to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT