213k views
2 votes
Type a statement using srand() to seed random number generation using variable seedVal. Then type two statements using rand() to print two random integers between (and including) 0 and 9. End with newline. Ex:

5
7

1 Answer

7 votes

Answer:

The solution code is written in C language.

  1. srand(seedVal);
  2. printf(" %d \\", rand() % 9);
  3. printf(" %d \\", rand() % 9);

Step-by-step explanation:

srand() is a C library function which seeds the random number generator. The srand() function will take one unsigned integer, seedVal, as input parameter (Line 1).

We can print random integer between (and including) 0 and 9 by calculating the random number modulus by 9 (Line 2-3). This will ensure the final random number will also be between 0 and 9.

User Andrew Schuster
by
6.2k points