निम्नलिखित का आउटपुट क्या होगा?
What will be the output of the following ?
def iq(a,b):
if(a==0):
return b
else:
return iq(a-1,a+b)
print(iq(3,6))
A)
B)
C)
D)
Explanation:
Sure!
The function iq
recursively calls itself, reducing a
and adding a
to b
each time.
iq(3, 6)
→iq(2, 9)
iq(2, 9)
→iq(1, 11)
iq(1, 11)
→iq(0, 12)
When a = 0
, it returns b
, which is 12
.
Answer: (D) 12.