Consider the following pseudo-code fragment in which an invariant for the loop is " m*xk =pnand k ≥ 0 " (Here, p and n are integer variables that have been initialized):

/* Pre-conditions:p ≥ 1 ∧ n ≥ 0 */

/* Assume that overflow never occurs */

int x=p; int k=n; int m=1;

while(k< >0)

{

if(k is odd) then m=m*x;

x=x*x;

k=⌊(k/2)⌋; /* floor(k/2) */

}

Which of the following must be true at the end of the while loop?

1
x=pn
2
m=pn
3
p=xn
4
p=mn

Sponsored

hivanix.in

Visit

This quiz is brought to you by hivanix.in

🌐 Web App Development

Quick Navigation