Consider the C program fragment below which is meant to divide x by y using repeated subtraction. The variables x, y, q and r are all unsigned int.

While (r >= y) {

r = r – y;

q = q + 1;

}

This question was previously asked in

GATE CS 2017 Official Paper: Shift 2

- (q == r) && (r == 0)
- (x > 0) && (r == x) && (y > 0)
- (q == 0) && (r == x) && (y > 0)
- (q == 0) && (y > 0)

Option 3 : (q == 0) && (r == x) && (y > 0)

Free

IBPS SO IT Officer Mains: Full Mock Test

4845

60 Questions
60 Marks
45 Mins

Given condition is x == (y*q + r)

Here, x= result, y= multiplicand, q= quotient, r= remainder

As, the number is divided using repeated subtraction, So quotient must be 0 in that case.

When in above condition q= 0

Then, x = r.

It matches with option 3.
India’s **#1 Learning** Platform

Start Complete Exam Preparation

Daily Live MasterClasses

Practice Question Bank

Mock Tests & Quizzes

Trusted by 2,17,91,872+ Students

Start your FREE coaching now >>

Testbook Edu Solutions Pvt. Ltd.

1st & 2nd Floor, Zion Building,

Plot No. 273, Sector 10, Kharghar,

Navi Mumbai - 410210

[email protected]
Plot No. 273, Sector 10, Kharghar,

Navi Mumbai - 410210

Toll Free:1800 833 0800

Office Hours: 10 AM to 7 PM (all 7 days)