21. Consider the following pseudo-code fragment in which an invariant for the loop is " m * xk = p nand 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?
/* 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?
ANS. B
Previous | Next |
UGC NET CS 2018 July - II Question 20 | UGC NET CS 2018 July - II Question 22 |
No comments:
Post a Comment