Ask Question
24 July, 20:43

Which of the following C+ + statements displays a random number in the range 1 through 10?

a)

cout << 1 + rand () % 10;

b)

cout << 1 + rand () % (10 - 1 + 1);

c)

cout << 1 + rand () % 10 - 1 + 1;

d)

first and second answers are correct

e)

all of the above

+2
Answers (1)
  1. 24 July, 22:30
    0
    Option (e)

    Explanation:

    rand () function results into a random number between 0 to a maximum number RAND_MAX which is a constant. To range it from 1, 1 is added and to decide its maximum value it should be modulo with that number. For example - if a number generated is 56 the 56%10 will be 6 which is in the range of 1 to 10. Option (a) is same as Option (b) because 1 is added and then subtracted which is neutral. Similarly, option (c) is also same.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Which of the following C+ + statements displays a random number in the range 1 through 10? a) cout ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers