Soru
Which one of the following statements correctly creates a random integer number between -50 and 50? Select one: a. int x=-50+rand()% 101 b. int x=50-rand()% 50 c. int x=-50+rand()% 50 d. int x=50-rand()% 100
Çözüm
4.4
(115 Oylar)
Eray
Elit · 8 yıl öğretmeni
Uzman doğrulaması
Cevap
The correct answer is option c: int
.Explanation:In this option, the expression
is used to generate a random integer number between
and
.The function `rand()` generates a random number between
and
, where
is a constant defined in the `` header file. The value of
is typically
on most systems.When we take the modulus of the result of `rand()` with
, we get a number between
and
. Adding
to this result gives us a number between
and
.Therefore, the expression
correctly generates a random integer number between
and
.