C语言 编程题:用循环嵌套的方法来实现s=1!+2!+3!+4!+5!

日期:2019-07-29 22:42:40 人气:1

C语言 编程题:用循环嵌套的方法来实现s=1!+2!+3!+4!+5!

#include #include int ans = 0; #define ans(n) for(int i = 1; i <= n; ++i)ans += calc(i, 1) int calc(int i, int tot) { if(i == 1)return tot; tot *= i; return calc(i - 1, tot); } int main() { ans(5); printf("%d", ans); return 0;
    A+
热门评论