Examine the following code and answer questions 7 below. IGNORE COMPILE ERRORS.
int j = 0;
for (j = 0; j <= 9; j++)
{ printf( “%d”, 1 + ( rand() % 5 )); }
7. What are the POSSIBLE range of numbers that will be printed by the “printf()” statement above?

Respuesta :

Answer:

1 to 5 both included.

Explanation:

rand() is the function which is used to generate the random values within the range.

for example:

rand() % 10;

it means it generate the output from 0 to 9. if we add the 1 in the above code:

like 1 + (rand() % 10);

Then, the range is from 1 to 10, it increase the range from start and end as well.

in the question code, for loop is used to for executing statement 9 times.

rand() % 5  

it generate the number from 0 to 4.

and 1 + ( rand() % 5 ))

it generate the output from 1 to 5

Therefore, the answer is 1 to 5.