Exercise: Testing a function
Consider the notion that an array int A[N] is ordered:
ordered(A[N]): forall i:1..N-1, A[i] >= A[i-1]
|
and some code to implement this test
ordered = 1;
for (i = 1; i < N; i++) {
if (A[i] >= A[i-1])
;
else
ordered = 0;
}
|
Put this code in a function and write a driver to test it.
Print "Yes" if ordered, or print "No" otherwise.
|