<!--factorial using functions-http://improvejavascript.blogspot.in/-->
<html>
<head>
<script type="text/javascript">
function factorial()
{
var n,f,i;
n=parseInt(form1.n1.value);
f=1;
for(i=1;i<=n;i++)
f=f*i;
form1.n2.value=f;
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="n1" /> <br>
<input type="text" name="n2" /> <br>
<input type="button" onclick="factorial()" value="Find Factorial" />
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function factorial()
{
var n,f,i;
n=parseInt(form1.n1.value);
f=1;
for(i=1;i<=n;i++)
f=f*i;
form1.n2.value=f;
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="n1" /> <br>
<input type="text" name="n2" /> <br>
<input type="button" onclick="factorial()" value="Find Factorial" />
</form>
</body>
</html>
No comments:
Post a Comment