Search Perform an advanced search query SOFTPEDIA
 
SOFTPEDIA
Updated one minute ago
HomeSubmit a program for being reviewedAdvertise on our websiteGet help on surfing our websitesSend us your feedbackGet information about our XML/RSS backend and how to use itBrowse the news archiveVisit our discussion forumVizitati forumul in limba romana



KLIP
  1. HOME
  2. SCIENCE
  3. TECHNOLOGY
  4. WEBMASTER
  5. SECURITY
  6. MICROSOFT
  7. LINUX
  8. APPLE
  9. GAMES
  10. TELECOMS
  11. REVIEWS
  12. LIFE & STYLE
  13. EDITORIALS
  14. INTERVIEWS
  15. RSS
Welcome!
Hello, Guest

Login if you have a Softpedia.com account.

Otherwise, register for one.

TIPS AND TRICKS

A Binomial Coefficient Calculator with JavaScript

- Recursive calculation of factorial numbers

By: Catalin Bocanu, Web News Editor

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
<html>
<script type="text/javascript">
function fact(n)
{ if (n <= 1)
return 1
else
return n * fact(n-1)
}
var n = 3
var k = 2
document.write(fact(n)/(fact(k)*fact(n-k)))
</script>
</html>


You can copy and paste the code in a new notepad window or any text editor and save it as calculator.html in order to test the script. The if statement takes into account the fact that 0!=1!=1. When the n variable takes a value lower than or equal with the unity the iteration stops. By changing the values of n and k variables, you will be able to find out the value of the corresponding binomial coefficient. You can perform further customizations to this script, such as the adding of an option to change the variable values using forms, without the need to manually edit the code.


MORE RELATED ARTICLES: Graphs and Charts with FusionCharts The Most Popular Free WYSIWYG Editors Random Webpages Free Download Jabber Clients Made With Javascript Elegant Solutions for Online Stores Automatic Text Translation with Javascript Get A Free Flash Image Gallery Selenium Tests Jaxer AJAX Server Methods To Promote Websites on Digg
 
Comments | Link here | Subscribe
Print | Send to friend
Today's News | Yesterday's News

Search:


13th May 2008, 15:54 GMT | Copyright (c) 2008 Softpedia | Contact:
Read by 909 user(s) | Rating: | 6 vote(s) so far | Cast your vote:
A Binomial Coefficient Calculator with JavaScript - USER OPINIONS




We are sorry, there are no opinions available for this article.






SHARE YOUR OPINION ABOUT A Binomial Coefficient Calculator with JavaScript

Since you are not logged on, your comments will have to be approved before being displayed.
Click here to login, or register.
Your Name:
Your Email:
Type in the result:
Your Opinion:
 


DO YOU WANT TO CONTACT US?  

If you have some comments or you want to send us some information you can send us an email directly to .
You can use the form below for the same purpose.
Your full name: (at least 3 characters)
Your email address: (at least 5 characters)
Message subject: (at least 5 characters)
Message text:
(at least 10 characters)
Type in the result:
 
 



© 2001 - 2008 Softpedia. All rights reserved.
Softpedia™ and Softpedia™ logo are registered trademarks of SoftNews NET SRL.
Copyright Information | Privacy Policy | Terms of Use | Contact Softpedia | Update your software | Archive