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...

Hiding worksheet tabs does not stop navigation to other worksheets in the workbook if hyperlinks have been created that allow the user to move from one sheet to another

Indicate whether the statement is true or false.

Computer Science & Information Technology

Answer the following statements true (T) or false (F)

1. The organizational changes in processor design have primarily been focused on increasing instruction-level parallelism so that more work could be done in each clock cycle. 2. With superscalar organization increased performance can be achieved by increasing the number of parallel pipelines. 3. The increasingly difficult engineering challenge related to processor logic is one of the reasons that an increasing fraction of the processor chip is devoted to the simpler memory logic. 4. The demand on power requirements has not grown as chip density and clock frequency have risen. 5. As chip transistor density has increased, the percentage of chip area devoted to memory has decreased.

Computer Science & Information Technology