Teaching UGC NET Mock Test Series 2025 (Paper 1 & 2) Programming and Data Structure Programming in C While Loop
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