递归
long recursin(int); void main() { int n; long result; printf("input a integer number: \n"); scanf("%d", &n); result = recursin(n); printf("%d! = %ld\n", n, result); } long recursin(int n) { long temp_result; if(n<0) { printf("n<0, input error!\n"); } else if(n == 0 || n == 1) { temp_result = 1; } else { temp_result = recursin(n-1) * n; } return temp_result; }
时间: 2024-10-23 03:22:41