编程论坛
注册
登录
编程论坛
→
C++教室
c++怎样编写阶乘的和
行者无疆。
发布于 2017-03-22 23:09, 1394 次点击
1!+2!+3!+4!+5!怎么编写
1 回复
#2
rjsp
2017-03-23 09:27
程序代码:
unsigned
foo(
unsigned
n )
{
unsigned
r =
0
;
for
(
unsigned
i=
0
,t=
1
; i!=n; t*=++i+
1
)
r += t;
return
r;
}
#include
<iostream>
using
namespace
std;
int
main(
void
)
{
cout
<< foo(
0
) << endl;
cout
<< foo(
1
) << endl;
cout
<< foo(
5
) << endl;
}
1