计算1!+2!+3!+……10!=4037913的程序.
答案:4 悬赏:70
解决时间 2021-11-06 02:32
- 提问者网友:
- 2021-11-05 11:45
急求答案..
最佳答案
- 二级知识专家网友:撞了怀
- 2021-11-05 12:09
public class Acctor {
private long re;
public long calculate(){
re = 0;
long te = 1;
for(int i=1; i<=10; i++){
te*=i;
re+=te;
}
return re;
}
public static void main(String[] a){
Acctor an = new Acctor();
System.out.println(an.calculate());
}
}
private long re;
public long calculate(){
re = 0;
long te = 1;
for(int i=1; i<=10; i++){
te*=i;
re+=te;
}
return re;
}
public static void main(String[] a){
Acctor an = new Acctor();
System.out.println(an.calculate());
}
}
全部回答
- 1楼网友:由着我着迷
- 2021-11-05 16:07
难!!!!!!!!!!!!!
再看看别人怎么说的。
- 2楼网友:蕴藏春秋
- 2021-11-05 15:10
int factorial(int n)
{
if (n == 0)
return 1;
return n * factorial(n - 1);
}
void main(void)
{
int ret = 0;
for (int i = 1; i <= 10; ++i)
ret += factorial(i);
printf("ret = %d\n", ret);
}
- 3楼网友:枭雄戏美人
- 2021-11-05 13:38
将以下代码复制到记事本后,另存为xxx.vbs
代码:
function sumn(n)
dim temp
temp=1:sumn=0
for i=1 to n
temp=temp*i
sumn=sumn+temp
next
End function
msgbox "1!+2!+3!+……10!="&sumn(10)
不知道你想用什么语言写.但算法可以借鉴,要是回答的内容有问题,或认为不妥,请发送百度消息给我,消息内容加上本页网址哦。。
·
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯