学了三个单词:factorial 阶乘,recursivly 递归地、iteratively迭代地
/*
** Compute the factorial of n, recursively 递归法计算阶乘
*/
long factorial( int n )
{
if( n <= 0 )
return 1;
else
return n * factorial( n - 1 );
}
/*
** Compute the factorial of n, iteratively 迭代法计算阶乘
*/
long factorial( int n )
{
int result = 1;
while( n > 1 ){
result *= n;
n -= 1;
}
return result;
}