Computer Sciences > Gate 2017 Set-2 > C code
Consider the C program fragment below which is meant to divide x by y using repeated subtractions. The variable x, y, q and r are all unsigned int.

while(r >= y)
{
    r = r - y;
    q = q + 1;
}


Which of the following conditions on the variables x, y, q and r before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)?
A
( q == r ) && ( r == 0)
B
( x <0 ) && ( r == x ) && ( y > 0 )
C
( q == 0 ) && ( r == x ) && ( y > 0 )
D
( q == 0 ) && ( y > 0 )

Correct : C code

Similar Questions

Consider the following C program. # include&lt;stdio.h&gt; int main( ) { &nbsp; &nbsp; static int a[] = {10, 20, 30, 40, 50}; &nbsp; &nbsp; static int *p...
#522 Fill in the Blanks
Consider the following C program. # include&lt;stdio.h&gt; int main( ) { &nbsp; &nbsp; static int a[] = {10, 20, 30, 40, 50}; &nbsp; &nbsp; static int *p...
#522 Fill in the Blanks
Consider the following C program. # include&lt;stdio.h&gt; int main( ) { &nbsp; &nbsp; static int a[] = {10, 20, 30, 40, 50}; &nbsp; &nbsp; static int *p...
#522 Fill in the Blanks

Related Topics

No tags found

Unique Visitor Count

Total Unique Visitors

Loading......