1 #include <stdio.h> 2 /* 3 题目:求n! 4 解题思路:0的阶乘 = 1 n的阶乘 =n*(n-1)! 5 */ 6 int fac(int n) 7 { 8 if(0 == n) 9 return 1; 10 else 11 return n*fac(n-1); 12 } 13 14 int main(void) 15 { 16 int n,n_fac; 17 printf("输入您想求的阶乘,退出输入q "); 18 gogogo: while(scanf("%d",&n) == 1) 19 { 20 n_fac = fac(n); 21 printf("%d! = %d ",n,n_fac); 22 printf("输入您想求的阶乘,退出输入q "); 23 goto gogogo; 24 } 25 26 return 0; 27 }