用Java编写一个程序,计算s=1+(1+2)+(1+2+3)+…+(1+2+3+4+5+…+100...
int sumI = 0;\/\/calc (1+2+3) for 3 for(int j = 1; j <= i; j++){ sumI = sumI + j;} sum = sum + sumI;} System.out.println("1+(1+2)+(1+2+3)+…+(1+2+3+4+5+…+100) = " + sum);} }
用VB写设计程序代码,求:s=1+(1+2)+(1+2+3)+??+(1+2+3+??+n)的值。
For i = 1 To n s = s + 1 \/ i Next i sumF = s End Function Private Sub Form_Click()sum1 = sumD(100)sum2 = sumF(100)Print Print "sum1="; sum1 Print "sum2="; sum2 End Sub 运行结果是:sum1=5.187377 sum2=5.187377 ...
用python自定义n,编写代码输出s=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)
else:return sum(range(1, n + 1)) + func(n - 1)例如:print(func(5))如果你要输出公式:def func1(n):if n == 1:return "1 "if n == 2:return "(1 + 2)"else:a_list = [ str(i) for i in range(1, n + 1)]return "(" + " + ".join(a_list) + ")"def ...
求S=1+(1+2)+(1+2+3)+···+(1+2+3+···+n)级数和的java程序算法_百 ...
public class Test { public static void main(String args[]){ int n=3,s=0,s_i; \/\/n是你要求多少项,s_i是每一项的和 for(int i=0;i<=n;i++){ s_i=i*(i+1)\/2; \/\/累加求和公式 s+=s_i;} System.out.println(s); \/\/n取的是3,答案为10,你也可以设置n为...
用while循环如何编写求1+(1+2)+(1+2+3)+...+(1+2+3+...+100)的程序
include <stdio.h> void main(){ long i=0,j=0,sum=0;while(i<101){ i++;j+=i;sum+=j;} printf("%ld\\n",sum);}
编程实现求Sum=1+(1+2)+(1+2+3)+(1+2+3+4)+ …… +(1+2+3+4+ … +...
Sub test()n = InputBox("输入一个整数")su = 0 For i = 1 To n * 1 For j = 1 To i - 1 su = su + j Next su = su + i Next Print su End Sub
编写一个程序,输入正整数n,计算s=1+(1+2)+(1+2+3)+...+(1+2+3+...
include <stdio.h> int fun(int n);void main(){ int i,n,sum=0;printf("请输入n:");\/\/输入数字,如10 scanf("%d",&n);for (i=1;i<=n;i++){ sum+=fun(i);} printf("sum=%d\\n",sum);} int fun(int n)\/\/计算和 { if(n==1)return 1;return n+fun(n-1);} ...
编写一个程序,由键盘输入n值,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n...
include <stdio.h>int main(){ int sum = 0, n;puts("enter n:");scanf("%d", &n);for (int i=1; i<=n; ++i){ for (int j=1; j<=i; ++j){ sum += j;} } printf("result: %d\\n", sum);return 0;}
输入n,计算S=1+(1+2)+(1+2+3)+(1+2+3+4)+...(1+2+3+...+n)
C语言版本:include<stdio.h> int main(){ int i,n;int Ni=0,S=0; \/\/Ni 表示第i项的值Ni=1+2+...+i;S为所求的值 printf("Please Input n: ");scanf("%d",&n); \/\/输入n for(i=1;i<n+1;i++){ Ni+=i; \/\/求第i项的值Ni S+=Ni; \/\/求S } printf("...
4,利用For循环求S=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)的值.提示:本题...
include <windows.h> int main(int argc, char* argv[]){ SetConsoleOutputCP(936);\/\/这是我的机器问题,你可以不用去管 long LInput(0);std::cin>>LInput;long LTemp(0);long LSum(0);for (long loopfor(0);loopfor<=LInput;++loopfor){ for (long loopIn(0);loopIn<=loopfor;...