递归求阶乘和

时间:2020-01-25 20:27:55   收藏:0   阅读:90

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 }

 

原文:https://www.cnblogs.com/2018jason/p/12233353.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!