program to find factorial of a number in javascript
factorial is basically multiplying a number with every number in descending order till it reaches to 0.
for example
2!=2*1*0
5!=5*4*3*2*1*0
note that 0!=1
for making this program in javascript,first you have to open notepad.
now type the following code in it
<html>
<head></head>
<title></title>
<body>
<script language="javascript">
var n=window.prompt("enter any number");
sum=n;
for(i=n-1;i>0;i--)
{
sum=sum*i;
}
window.alert("the factorial is"+sum);
</script>
</body>
</html>
now goto file and save it as factorial.html
this will appear on the destination place and open it with the help of browser and you will see the factorial of that number.



0 comments: