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);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.