#include <stdio.h>
#include <math.h>
int factorial( int n )
{
int result, recurse;
if ( n == 0 ){
result = 1;
} else {
recurse = factorial( n-1 );
result = n * recurse;
}
return result;
}
int main ( int argc, char **argv )
{
int x, y;
scanf("%d", &x);
y = factorial(x);
printf("%d! = %d", x, y);
return 0;
}
利用递归求n!
最新推荐文章于 2024-03-13 08:41:37 发布