Please check code for Recursion-Keypad Codes problem

hello @sahilkhan2312000131

check now->

u were using same ans variable for storing subproblem result and total result
becuase of that ur answer was coming different

I am not getting why have you written result=0; above for loop of itr?

see each subproblems are treated as independet problem right?
and making new function call is equivalent to solving new subproblem right?
so for each independent problem what would be our initial answer it will be 0 right?
and later we use loop to compute all its combintation.
this was the reason why i initilaised result with 0

Coding Blocks IDE
Please see this code, can you tell me why the output has 6 just after 3?

bro why are u making result as global variable.
for new subproblem we want new variable variable.
making it global will give weired results only becuase it will add up answer of all subproblems.

wait let me share u a simpler approach that uses global variable

see this ->

I am getting your point that I should not make result as global variable. But can you tell me what is the reason for getting 6 just after 3 as output? I am dry running the code and not getting this thing.

it it the summation of 1+2+3 that i was talking about->

thank you so much for your time @aman212yadav

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.