Factorial · Giả thừa
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.)
Giai thừa
Giai thừa n! là tích 1 * 2 * 3 * ... * n. Theo định nghĩa 0! là 1.
Khởi tạo kết quả ở 1, sau đó nhân nó với từng số nguyên từ 2 đến n trong vòng lặp. (Các bài kiểm tra giữ n tối đa 10, nên đáp án vừa khít trong kiểu dữ liệu int.)
Complete int factorial(int n) to return n! = 1 * 2 * ... * n. Assume 0 <= n <= 10, and factorial(0) is 1. · Hoàn thành int factorial(int n) để trả về n! = 1 * 2 * ... * n. Giả sử 0 <= n <= 10, và factorial(0) là 1.
Click Run to see the output here. · Nhấn Chạy để xem kết quả ở đây.