0

How it continues the process without any loop? Or how recursion is working in this code?

https://code.sololearn.com/cYBIXjC0jH78/?ref=app

26th Apr 2021, 3:41 PM
Atul
Atul - avatar
4 Respuestas
+ 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)
26th Apr 2021, 4:15 PM
TOLUENE
TOLUENE - avatar
+ 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 !
26th Apr 2021, 3:50 PM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
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
26th Apr 2021, 4:02 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
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
27th Apr 2021, 8:03 AM
Atul
Atul - avatar