iqramehmood586 iqramehmood586
  • 21-05-2021
  • Computers and Technology
contestada

Write a c++ program that generates three random numbers. The first number should be between 0-30, the second number should be between 30-60 and the third number should be between 60-90.

Respuesta :

tonb
tonb tonb
  • 21-05-2021

Answer:

#include <stdlib.h>

#include <time.h>  

#include <iostream>

using namespace std;

int main() {

   srand(time(NULL));

   cout << rand() % 30 << endl;

   cout << rand() % 30 + 30 << endl;

   cout << rand() % 30 + 60 << endl;

}

Explanation:

rand() returns a pseudo-random integral number in the range between 0 and RAND_MAX. By applying the modulo operator, you map that to the desired range (30 in your case), then you add an offset.

Answer Link

Otras preguntas

Which of the following sentences best states the main idea of " the literature of the Americans"
What is the answer to this problem I am struggling with it
Part 3—Dictation and Listening Comprehension The listening passage for this examination consists of two poems. You’ll hear the poems three times. These poems ar
Which reading strategy is best when you are trying to make sense of and retain the information in a textbook?
34-17 in word expression
Given that x is a whole number, Niram conjectured that x3>x2 . What value is a counterexample to Niram's conjecture? A.) −2 B.) 110 C.) 1 D.) 5
What is the equation of a vertical line passing through (5, -7)
How did the railroads respond to state governments legislation during the gilded age?
The Executive branch must receive approval from _________ when appointing heads of executive departments, ambassadors, and Federal Court Judges. a. the House of
7,801 + blank = 4,890 + 7,801