Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Last active December 29, 2017 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mmloveaa/c3be63d80dbdd3ffd2e98d0505bf6a0f to your computer and use it in GitHub Desktop.
Save mmloveaa/c3be63d80dbdd3ffd2e98d0505bf6a0f to your computer and use it in GitHub Desktop.
4-19 Q2 Calculate Factorial
Write a program that will read an integer N from STDIN and compute the factorial of N. The input to your program will contain many lines. On each line there will be exactly one integer. Your program should print the factorial of each integer in a separate line. Your program should terminate when it reads a number that is not positive.
1 <= N <= 15
Sample Input
1
2
3
-1
Sample Output
1
2
6
process.stdin.resume();
process.stdin.setEncoding("ascii");
var input = "";
process.stdin.on("data", function (chunk) {
input += chunk;
});
process.stdin.on("end", function () {
// now we can read/parse input
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment