C program for finding the binomial co-efficient is given in the link below.

This program gives right answer.But I want what is (recbicoff(n-1,r-1) recbicoff(n-1,r))
in the program.Please explain.

1 Like

you have forgot a ‘return’ in the ‘if’ statement for r>n. It should be

if(r>n){
    printf("The value of n can't be less than r");
    return;
}
1 Like

u can use dynamic programming too…see this…tp7lGJ - Online C Compiler & Debugging Tool - Ideone.com

1 Like

Can you explain the last line in the program.

But this one have a problem if r>n this will not show any result and this one is much complex also.

are you talking about this statement? -

return(recbicoff(n-1,r-1)+recbicoff(n-1,r));

Do you know this property of combination?

nCr = (n-1)Cr + (n-1)C(r-1)

you can check Pascal’s triangle ( Pascal's triangle - Wikipedia )

1 Like

You can memoize to reduce the computation. At the beginning of the code, just create a pascal’s triangle using a 2D array. And add a condition for r>n for each input.

Can you say why we are not using ncr directly,please.

Because nCr =(n!)/((n-r)!(r!)) . For large n, n! will overflow the range and will produce wrong answer. That’s why we can’t simply compute it by this formula. We have to use other properties or techniques to compute nCr.

1 Like

If my answer is clear to you, you can mark it as ‘accepted answer’. This will help others to find the best answer. Thank you.