Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For each of the followings, state the precondition or/and postcondition. (3) i =

ID: 3852035 • Letter: F

Question

For each of the followings, state the precondition or/and postcondition.
(3) i = 1; c = 0; while (i <= n) { if (a[i] == 17) c = c + 1; i = i + 1; } (4) m = a[1]; i = 2; while (i <= n) { if ( a[i] > m ) m = a[i]; i = i +1;
For each of the followings, state the precondition or/and postcondition.
(3) i = 1; c = 0; while (i <= n) { if (a[i] == 17) c = c + 1; i = i + 1; } (4) m = a[1]; i = 2; while (i <= n) { if ( a[i] > m ) m = a[i]; i = i +1;
For each of the followings, state the precondition or/and postcondition. For each of the followings, state the precondition or/and postcondition.
(3) i = 1; c = 0; while (i <= n) { if (a[i] == 17) c = c + 1; i = i + 1; } (4) m = a[1]; i = 2; while (i <= n) { if ( a[i] > m ) m = a[i]; i = i +1;

Explanation / Answer

(3) i = 1;

c = 0;

while (i <= n) {

if (a[i] == 17) c = c + 1;

i = i + 1; }

Answer: The post condition for the above precondition loop is

i = 1;

c = 0;

do {

if (a[i] == 17) c = c + 1;

i = i + 1; } while (i <= n);

(4) m = a[1];

i = 2;

while (i <= n) {

if ( a[i] > m ) m = a[i];

i = i +1;

Answer: The post condition for the above precondition loop is

m = a[1];

i = 2;

do {

if ( a[i] > m ) m = a[i];

i = i +1; } while (i <= n);