Recursive calculation of factorial numbers

May 13, 2008 15:54 GMT  ·  By

The web based calculators are widely used due to the fact that they usually do not require the installation of a third party software in neither of the known operating systems. Calculators that come with client side programming languages as JavaScript imply the execution of the code on the client side and they require only a compatible web browser.

There are many free JavaScript calculators that perform almost any type of mathematical or statistical operations, like the value of factorial function for various integer numbers. A factorial number is defined as follows: n! = 1 x 2 x 3 x ... x (n-1) x n, where n is an integer.

In case you want to automate the calculation of binomial coefficient values with the help of JavaScript, an efficient algorithm must be chosen. The most common used algorithm in calculation of factorial value is recursion. In any recursion method a function is generated during an iteration. As a consequence, the factorial of n can be defined recursively like: n!=(n-1)! X n.

The binomial coefficient is defined as C(n,k)=n!/(k! X (n-k)!). The next JavaScript code will allow you to calculate the value of any binomial coefficient in case of integers:

[CODE=0]

function fact(n) { if (n