C语言调试示例

递归求阶乘和

 1 #include<stdio.h>
 2 long Recursion(int n) {
 3     if (n == 1 || n == 0) {
 4         return 1;
 5     }
 6     else {
 7         return  Recursion(n - 1) * n;
 8     }
 9 }
10 int main()
11 {
12     int flag = 1;
13     int n = 0;
14     printf("输入负数结束程序\n");
15     while (flag) {
16         printf("输入:");
17         scanf_s("%d", &n);
18         if (n < 0)
19             flag = 0;
20         long sum = 0;
21         if (n >= 0) {
22             for (int i = 1; i < n; i++) {
23                 sum += Recursion(i);
24                 printf("%d!+", i);
25             }
26             sum += Recursion(n);
27             printf("%d!=%ld\n", n, sum);
28         }
29     }
30     return 0;
31 }

 

posted @ 2020-11-24 15:41  Wind·Chaser  阅读(191)  评论(0编辑  收藏  举报