Anasayfa
/
Teknoloji
/
Which One of the Following Statements Correctly Creates a Random Integer Number Between -50 and 50? Select One: A. Int X=-50+rand()%

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
Uzman doğrulaması
Elit · 8 yıl öğretmeni

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 .