0
How it continues the process without any loop? Or how recursion is working in this code?
4 ответов
+ 2
5*fac(4)
5*4*fac(3)
5*4*3*fac(2)
5*4*3*2fac(1)
5*4*3*2*1 //base case meets so recursion stops at fac(1)
+ 1
Hey Atul ,
call for fac(5) , goes in function ,if condition doesn't satisfied, so it goes for else : 5* fuc(4) , again call to same function , if condition doesn't match this time also , so it goes in else : 5*4*fac(3) ,it goes up to 5*4*3*2*fac(1) , and if condition will satisfied , it returns 1 .
So final expression will be 5*4*3*2*1=120 will be printed !
0
Here your Recursive function fac(n) Calling again and again till upto n==0 ||n==1 if your value will be 0 or 1 it will stop functions is calling again an again and value of n is decreasing by 1
So values will calculate lile this
5*4*3*2*1 here it will return values if n will be 1 or 0
0
Are recursion a property of loops. As in looping Repeitation takes place and in recursion too. So can I say both carries certain similarty