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

    printf("The value of n can't be less than r");
1 Like

Can you explain the last line in the program.

u can use dynamic programming too…see this…https://ideone.com/tp7lGJ

1 Like

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? -


Do you know this property of combination?

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

you can check Pascal’s triangle ( https://en.wikipedia.org/wiki/Pascal’s_triangle )

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.