Solved

The Following While Loop Is Annotated with a Pre- and Post-Condition

Question 21

Essay

The following while loop is annotated with a pre- and post-condition and also a loop invariant.
Use the loop invariant theorem to prove the correctness of the loop with respect to the pre- and post-conditions.
[[ Pre-condition: product =A[1]= A [ 1 ] and i=1]i = 1 ] while (im)( i \neq m )
1. i:=i+1i : = i + 1
2. product := product. A[i]A [ i ]
end while
[[ Post-condition: product =A[1]A[2]A[m]]= A [ 1 ] \cdot A [ 2 ] \cdots A [ m ] ]
loop invariant: I(n)I ( n ) is "i=n+1" i = n + 1 and product :=A[1]A[2]A[n+1]": = A [ 1 ] \cdot A [ 2 ] \cdots A [ n + 1 ] "

Correct Answer:

verifed

Verified

Proof:
I. Basis Property: blured image is the statem...

View Answer

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions