Factorial (mind the size) · المضروب (انتبه للحجم)
Factorial (mind the size)
n! is 1 × 2 × … × n, and 0! is 1. It grows fast — 20! is over two billion billion — so the method returns a long, not an int, or the answer would overflow. Multiply from 2 up to n.
المضروب (انتبه للحجم)
n! هو 1 × 2 × … × n، و0! هو 1. ينمو بسرعة — 20! يتجاوز تريليون تريليون — لذا تُرجع الطريقة long بدلاً من int، وإلا سيحدث طفح في الإجابة. اضرب من 2 حتى n.
Complete factorial(int n) returning n! as a long (so large values fit). factorial(0) is 1. Assume 0 <= n <= 20. · أكمل factorial(int n) تُرجع n! كـ long (لكي تتسع القيم الكبيرة). factorial(0) هي 1. افترض 0 <= n <= 20.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.