+ 1
When n=5 If condition is not true so second statement will execute according to that : 1. When n= 5, 3+ r(4) //because (n-1=5-1=4) 2. This time n= 4 which is again not equal to 1 or smaller than that. So, seconds statement. 3+ 3+ r(3) //(n-1= 3-1=2) 3. Again n= 3 which is again not equal to 1 or smaller than that. So, seconds statement. 3+ 3+ 3+ r(2) //(n-1= 3-1=2) 4. n= 2 which is again not equal to 1 or smaller than that. So, seconds statement. 3+ 3+ 3+3+ r(1) //(n-1= 2-1=1) 5. This time n=1 and it's satusfy the if condition so, it will execute first statement and return 20 3+3+3+3+20= 32. And that is final answer... Still if u didn't understand go through the recursive problem videos.
5th Aug 2022, 2:53 PM
Pallavi Jha
Pallavi Jha - avatar