Respuesta :
Answer:
#include <stdlib.h>
#include <time.h>
#include<iostream.h>
int main(void) {
int seedVal = 0;
seedVal = 4;
srand(seedVal);
/* Solution*/
cout<<rand() % 149 + 100<<endl;
cout<<rand() % 149 + 100<<endl;
return 0;
}
Explanation:
We start with the required include statements to enable use of srand, rand and time functions. I have also added iostream library to use "cout" function.
After that, the seed is initialized using srand(). And then the two rand functions are called with ranges including and between 100 and 149, and printed out.
Answer:
#include
#include // Enables use of rand()
#include // Enables use of time()
int main(void) {
int seedVal = 0;
seedVal = 4;
srand(seedVal);
cout<< rand()%(int)(149-100+1) + 100;
cout<< rand()%(int)(149-100+1) + 100;
return 0;
}
Explanation:
The code segment starts at line 8 and ends at line 9.
That is:
cout<< rand()%(int)(149-100+1) + 100;
cout<< rand()%(int)(149-100+1) + 100;
The syntax for generating random values in C using rand function is
rand()%(int)(max - min + 1) + min
Or
min + rand()%(int)(max - min + 1).
It works both ways..
Where max and min represent the range of values needed (maximum and minimum)
The random statement can also be used in loops