Factorial · 阶乘
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
Factorial
The factorial n! is the product 1 * 2 * 3 * ... * n. By definition 0! is 1.
Start a result at 1, then multiply it by every integer from 2 up to n in a loop. (The tests keep n at most 10, so the answer fits in an int.)
中文
阶乘
阶乘 n! 是连乘积 1 * 2 * 3 * ... * n。按照定义,0! 等于 1。
把结果初始化为 1,然后用循环把它依次乘以从 2 到 n 的每个整数。(测试中 n 最大为 10,所以结果能放进一个 int。)
Complete int factorial(int n) to return n! = 1 * 2 * ... * n. Assume 0 <= n <= 10, and factorial(0) is 1. · 完成 int factorial(int n),返回 n! = 1 * 2 * ... * n。假设 0 <= n <= 10,且 factorial(0) 为 1。
Click Run to see the output here. · 点击“运行”查看此处输出。