递归求阶乘和

https://pintia.cn/problem-sets/12/problems/352

复制代码
 1 double fact(int n)
 2 {
 3     double product;
 4     if (n == 0)
 5     {
 6         product = 1;
 7     }
 8     else
 9     {
10         product = n * fact(n - 1);
11     }
12 
13     return product;
14 }
15 double factsum(int n)
16 {
17     double result = 0;
18     for (int i = 1; i <= n; i++)
19     {
20         result = result + fact(i);
21     }
22 
23     return result;
24 }
复制代码

 

posted @   jason2018  阅读(634)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示