c++ 递归思想 阶乘

 1 #include "stdio.h"
 2 #include "iostream"
 3 
 4 long fact(int n);
 5 
 6 int  main()
 7 {
 8     int i;
 9     scanf("%d", &i);
10     printf("%d 的结成结果为: %ld\n",i,fact(i));
11     system("pause");
12     return 0;
13 }
14 
15 long fact(int n)
16 {
17     if (n <= 1)
18         return 1;
19     else
20         return n*fact(n - 1);
21 }

猜你喜欢

转载自www.cnblogs.com/zhibei/p/11145780.html
今日推荐