This program gives right answer.But I want what is (recbicoff(n-1,r-1) recbicoff(n-1,r))
in the program.Please explain.
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;
}
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 ( https://en.wikipedia.org/wiki/Pascal’s_triangle )
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.
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.