JavaScript :- Factorial
This is JavaScript Practical :- Factorial.
Script written in small letter because JavaScript Case Sensitive.
Script:-
<html>
<head>
<title>Factorial</title>
<script type="text/javascript">
// This is factorial in function
function show()
{
var i, no, fact;
fact=1;
no=Number(document.getElementById("num").value);
for (i = 1; i <= no; i++)
{
fact = fact * i;
}
document.getElementById("answer").value = fact;
}
</script>
</head>
<body>
enter the number : <input id="num"><br>
<button onclick="show()"> Factorial</button><br>
<input id="answer">
</body>
</html>
Save the File .html
Output:-
If you have any doubts mention on the Comment Box.
Please follow the my Blog, Share and Comment.
Comments
Post a Comment