Binary Coefficient

To get a program that calculates the binary coefficient of a number:

// Warning! This code may be inaccurate in syntax or may not work properly.
// Please refrain from using it.
// This function is recursive
 
function binarycoefficient(a,b)//taking -1<b<=a
{
if
(b==0 || b==a)
{
result=1;
}
else if (b<0 || a<0)
{
alert("Error. There is a negative value.");
}
else if (b>a)
{
c=a;
a=b;
b=c;
}
if (isNaN(result))
{
result = binarycoefficient(a-1,b-1)+binarycoefficient(a-1,b);
}
return result;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License