for (index = 1; index <= 4; index++)
cout << ' ' << arr[index];
Instead, the code printed 20 30 40 24835. Explain the reason for this output.
9. Given the declarations
int sampIe [8];
int i;
int k;
show the contents of the array sample after the following code segment is executed. Use a question mark to indicate any undefined values in the array.
for (k = 0; k < 8; k++)
sample[k] = 10 - k;
10. Using the same declarations given for Exercise 9, show the contents of the array sample after the following code segment is executed.
for (i = 0; i < 8; i++)
if (i <= 3)
sample[i] = 1;
else
sample[i] = -1;
11. Using the same declarations given for Exercise 9, show the contents of the array sample after the following code segment is executed.
for (k = 0; k < 8; k++)
if (k % 2 == 0)
sample[k] = k;
else
sample[k] = k + 100;
Programming Warm-Up Exercises
Use the following declarations in Exercises 1-8. Assume the data type Boolean already has been definned. You may declare any other variables that you need.
const int MAX_STUD = 100; // Max. number of students
Boolean failing [MAX_STUD ];
Boolean passing [MAX_STUD];
int grade;
int length;
int score[MAX_STUD];