www.ypnh.net > jAvA已知s=1!+2!+3!+...+7!.编写程序计算s的值.利...

jAvA已知s=1!+2!+3!+...+7!.编写程序计算s的值.利...

#include <stdio.h>int main(){ int i,s=0;for(i=1;i<=100;++i) s += i; printf("s=%d", s);return 0;}

2 ,3 楼答案给了

这个用单层循环就可以解决的.没必要用双循环

//用java编写一个程序,计算s=1+(1+2)+(1+2+3)+…+(1+2+3+4+5+…+100).public class sum { public static void main(string[] args) { int sum1 = 0; int sum = 0; for (int i = 1; i { sum1 += i; sum += sum1; } system.out.println(sum); }

s=0;i=1 ?Do s=s+i i=i+1 Loop until i>100 Print s

public class Sum{double fact(int x){if(x==1){return 1;}else{return x*fact(x-1);}}public static void main(String[] args){int s=0;for(int i=1;i 评论0 0 0

你的程序是不对,当I=3时,S加的是3*1+3*2+3*3,而不是 3*2*1 正确程序如下: set talk off clear s=0 for i=1 to 5 p=1 for j=1 to i p=p*j endfor s=s+p ?s endfor ?s

int sum=0; int s=0; for(int i=1;i

添加一个Button,一个text双击Button,在代码(End Sub之前)之间添加如下语句:int iint s=0for i=1 to 100s=s+inexttext1.text=s

private static void Main(string[] args) { int sum = 0; for (int i = 1; i { sum += i; } Console.WriteLine("1加到100的和为: "+sum); }

网站地图

All rights reserved Powered by www.ypnh.net

copyright ©right 2010-2021。
www.ypnh.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com