Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
po有人可以向我解释这段代码吗?它是使用迭代的幂函数
public static int iterate(int a, int n) { int i ; int result = 1 ; for(i = 0 ; i < n ; i++){ result = result*a ; } return result ; }
它有助于了解阶乘的定义:
0! = 1 1! = 1 2! = 2*1 = 2 3! = 3*2*1 = 6 4! = 4*3*2*1 = 24 n! = n*(n-1)*(n-2)*...*2*1
看到图案了吗?
您发布的内容在我看来更像a^n = a*a*a...*a,而不是阶乘。
a^n = a*a*a...*a