Because 2nd one is calculating ncr(n-1, k) instead of ncr(n-1, k-1)
Example for ncr(27,20) it should return 657800 i.e. N = 26 and K = 19
It is returning 230230 instead. i.e N = 26 and K = 20
Thank you for pointing that out.
That was due to me ignoring the case when the “if” statement is executed and the value of n is changed to n-r.
I removed it and changed it to n-r+1. It works fine now.
Thanks a lot.
Cheers