Consider the following recursive function.

Int function (int x, int y) {

If (y <= 0) return x;

return function (y, x%y);

}

The above recursive function computes ______.

This question was previously asked in

CIL MT Systems: 2020 Official Paper

- y
^{x} - GCD of x and y
- x
^{y} - LCM of x and y

Option 2 : GCD of x and y

Free

ST 1: General Awareness

7043

15 Questions
15 Marks
15 Mins

Consider x = 10 and y = 25

__CASE1: __

If (y <= 0) return x; // 25<=0 (false)

return function (y, x%y); return function(25, 10)

__CASE 2:__

x = 25, y= 10

If (y <= 0) return x; // 10<=0 (False)

return function (y, x%y); // return function (10, 5)

__CASE 3:__

x =10, y =5

If (y <= 0) return x; // 5<=0 (false)

return function (y, x%y); //return function(5, 0)

__CASE 4:__

x = 5, y =0

If (y <= 0) return x; // condition true, return 5

return function (y, x%y);

Output = 5

Which is greatest common divisor of 10 and 25.

So, given program computes GCD of x and y

India’s **#1 Learning** Platform

Start Complete Exam Preparation

Daily Live MasterClasses

Practice Question Bank

Mock Tests & Quizzes

Trusted by 2,29,86,569+ Students

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)