215k views
4 votes
write a pseudocode statement that generates a random number inthe range of 1 through 100 and assigns it to a variable namesrand.

User Londonfed
by
6.8k points

1 Answer

2 votes

Answer:

srand(time(NULL));

int namesrand = rand() % 100 +1;

Step-by-step explanation:

srand() is the function which is used for seeding the rand() function.

it defines the starting point different in whenever rand() function executes. Therefore, rand() generate the output different in every execution.

rand() is the function that generates the random number within the range.

for example;

rand() % 20

it generates the random number within the range [0,20).

NOTE: 20 not included in the range and zero is included.

similarly, generate the number between 0 to 99.

rand() % 100.

so, if we add the generated number by one then it ranges become 1 to 100 both included.

User Surez
by
6.3k points