Suppose we want an array to satisfy the condition,

```
a[0] <= a[1] <= a[2] <= ...
```
And suppose this code is written to implement a test of this condition
```
#include using namespace std;int main(){
double array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };//
assume the array is filled somehow.for(int i=0; i < 10;
i++) if (array[i] > array[i+1]) cout < elements << i << i + 1 << are out of order.\n";
```
When this is run, we sometimes get the following puzzling output:
```
Array elements 9 and 10 are out of order.
Even more puzzling, sometimes we don’t get this output.
Why?
```
What will be an ideal response?


There is an index out of range. When index i has value
```
9, i + 1 is 10,
so a[i+1],
```
which is the same thing as
```
a[10]
```
causes an illegal access. The loopshould stop with one fewer iterations. To correct this code, replace the for loop header
with
```
for(int i=0; i < 9; i++)
```

Computer Science & Information Technology

You might also like to view...

Provide an example of a distributed computation that would be difficult to implement in MapReduce, giving full reasons for your answer.

What will be an ideal response?

Computer Science & Information Technology

The components of a class are called the ____  of the class.

A. operators B. friends C. objects D. members

Computer Science & Information Technology

Which of the following is NOT an option in the Paste Options menu?

A. Keep Source Formatting B. Merge Formatting C. Keep Text Only D. Match Formatting

Computer Science & Information Technology

___________, sometimes called overloading, is the ability to redefine a method in a subclass.?

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology