Q. Consider the following Python function Fn(), that takes an integer n parameter and works recursively as follows:

 

def Fn(n):

    print(n, end=" ")

    if n< 3:

        return n

    else:

        return Fn(n // 2) - Fn(n//3)

 

What will be the result produced by following function calls?

 

(a) Fn(12)

(b) Fn(10)

(c) Fn(7)

 

Answer =

 

(a) Result produced by Fn(12) is:

 

12 6 3 1 1 2 4 2 1 -3

 

(b) Result produced by Fn(10) is:

 

10 5 2 1 3 1 1 1

 

(c) Result produced by Fn(7) is:

 

7 3 1 1 2 -2

 

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post