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

What is the function of the relative pronoun in the clause? States whose regulations ban the harvesting of animals from tide pools also prohibit the removal o
Why are a variety of instruments needed to measure change in the climate system?
Divide 500 grams into the ratio 2:3
the increase in trade and commerce during the middle ages resulted in
How do you turn 40/4 into a mixed number?
Based on your knowledge of Greek roots, what does philanthropist mean? a. Phil means "linger" and anthro means "charity" b. Phil means "like" and anthro means "
What role did john Adams play after the boston massacre and why?
A secondary source is reliable and credible of the person who created the source is an expert on the topic, is educated and respected in the field of study, and
Find the least common denominator (LCD) for the fractions.1\6 and 3\10 A. 2 B. 10 C. 30 D. 60
what times what equals 3000