Factorial · פאקטוריאל
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) כדי להחזir n! = 1 * 2 * ... * n. הנח כי 0 <= n <= 10, ו-factorial(0) הוא 1.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.