174k views
4 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 Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, srand() has already been called; do not call srand() again.

User PC Luddite
by
4.4k points

1 Answer

3 votes

Answer:

srand(time(NULL)); //using srand once

cout<< (rand()%50)+100; // first random number

cout<<endl; //new line

cout<< (rand()%50)+100; //second random number

Step-by-step explanation:

The srand function in C++ seeds the rand function. It means that the srand function provides rand function with a number which is used by the random function to generate random numbers.

User PhilB
by
4.4k points