Create a pseudocode program that asks the user to enter an integer number from 1
ID: 3684290 • Letter: C
Question
Create a pseudocode program that asks the user to enter an integer number from 1 to 20, and then calls a function to compute the factorial of this number. A factorial is the product of an integer times each smaller integer down to 1. For example, the factorial of 5 is 5*4*3*2*1 and has the value of 120. (Hint: Set a result variable to 1, and then use a For loop that multiplies the result variable by every number from the given number down to 1.) Use Notepad to create the program and post here and convert the pseudocode file to javaScript, and test your program. Save the file as factorial.html
Explanation / Answer
<!doctype html>
<html>
<head>
<script>
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 Num: <input id="num">
<button>Factorial</button>
<input id="answer">
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.