Definition:-
- when a function call itself is called recursion.
Example:-
Explanation:-
1) a fun function declared which takes argument and return value
2) main starts fun is called by passing 3 value
3)after calling fun definition starts, where check if a==1 no because a is 3, s=a+fun(a-1) means s=3+fun(2) from here fun function is again called now this body again execute now a is 2, so s=3+fun(2), fun(2) is replaced by 2+fun(2-1=1) i.e s=3+2+fun(1) again fun function is called...
overall s=3+2+1=6, s is return this return value goes where fun function is called , where return value is stored in k, so k=6 now print is 6.
Comments
Post a Comment