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 <iostream>
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 << "Array elements " << i << " and "
<< 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?
Correct Answer:
Verified
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q22: Explain the error in the following code.You
Q23: Here is a list of 8 numbers.Use
Q24: Consider the declaration
double a[10] = {1.2,2.1,3.3,3.5,4.5,7.9,5.4,
8.7,9.9,1.0};
Write a
Q25: Given the definition and code fragment: int
Q26: Given the array declaration,int a[20];The first element
Q28: Insert const before .any of the following
Q29: What is the output of the
Q30: Write the selection sort algorithm for an
Q31: What is the problem with this code?
int
Q32: Assume you have a swap routine in
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents