Write statements that assign random integers to the variable n in the following ranges:

a) 1 ? n ? 2
b) 1 ? n ? 100
c) 0 ? n ? 9
d) 1000 ? n ? 1112
e) –1 ? n ? 1
f) –3 ? n ? 11


a) 1 ? n ? 2
ANS: n = 1 + rand() % 2;
b) 1 ? n ? 100
ANS: n = 1 + rand() % 100;
c) 0 ? n ? 9
ANS: n = rand() % 10;
d) 1000 ? n ? 1112
ANS: n = 1000 + rand() % 113;
e) –1 ? n ? 1
ANS: n = rand() % 3 - 1;
f) –3 ? n ? 11
ANS: n = rand() % 15 - 3;

Computer Science & Information Technology

You might also like to view...

To assign the contents of one array to another, you must use

a. the assignment operator with the array names b. the equality operator with the array names c. a loop to assign the elements of one array to the other array d. Any of these e. None of these

Computer Science & Information Technology

The Styles window is a pane that displays a list of styles and contains tools to manage the styles

Indicate whether the statement is true or false

Computer Science & Information Technology

Depending on the manufacturer of the BIOS, what two different POST beep code sequences indicate a memory error?

A. continuous short beeps B. continuous three short beeps and then a pause C. continuous two short beeps and then a pause D. eight short beeps

Computer Science & Information Technology

Which of the following is NOT an option for configuring page margins on the Margins menu?

A. Normal B. Formatted C. Wide D. Narrow

Computer Science & Information Technology