Type two statements that use rand0 to print 2 random integers between (and inclu
ID: 2267938 • Letter: T
Question
Type two statements that use rand0 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 rand0 in a different order), Use two statements for this activity. Also, srand0 has already been called; do not call srand) again. 1 #include 2 #include stdlib.h> 3 #include // Enables use of rand() // Enables use of tine() 5 int main(void) 6 int seedval 8 seedval 4 9 srand(seedVal); 18 11 Your solution goes here 12 13 return e 14 )Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int seed = 100; //setting starting seed value i.e. 100
srand(seed);
printf("%d ", (rand() % 50 ) + 100 ); // (rand() %(max - min + 1)) + min
printf("%d ", (rand() % 50 ) + 100 ); // (rand() % (max - min + 1)) + min
return 0;
}
OUTPUT :-
140
101
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.