98.1k views
3 votes
Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline.

Ex: 101 133

User Alex Chuev
by
7.4k points

1 Answer

0 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

cout<< rand() % 50 + 100 <<endl;

cout<<rand() % 50 + 100 <<endl;

return 0;

}

Step-by-step explanation:

The rand() gives you a random number. If you use rand() % 50, it will give you a random number between 0 and 49. Since we are required to have the numbers between 100 and 149, add 100 to this expression. This way, you will have a random number between 100 and 149. Type this expression two times and use "endl" to end with a new line.

User Ayohaych
by
6.5k points