Skip to content

Commit 4b3a0ed

Browse files
committed
[Shreyash]: Added code to print factorial of entered number
1 parent 0731cc2 commit 4b3a0ed

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Write a program that computes a factorial of a number taken as input.
3+
5 Factorial => 5! = 1 * 2 * 3 * 4 * 5
4+
*/
5+
6+
const prompt = require("prompt-sync")();
7+
console.log();
8+
let number = parseInt(prompt(" Enter the number : "))
9+
let factorial = 1;
10+
for (let i = 1; i <= number; i++) {
11+
factorial = factorial * i;
12+
}
13+
console.log(" Factorial of " + number + " = " + factorial + "\n");

0 commit comments

Comments
 (0)