c语言s=1+(1+2)+(1+2+3)+…+(1+2+3+……+n)的值先编写一个求1+2+...
int sum,n;sum=0;printf("请输入n:\\n");scanf("%d",&n);for(int i=1;i<=n;i++)sum=sum+sumn(i);printf("%d",sum);}
...n值,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值。
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;}
用VB写设计程序代码,求:s=1+(1+2)+(1+2+3)+??+(1+2+3+??+n)的值。
Function sumD(n As Integer) As Single s = 1 i = 1 Do i = i + 1 s = s + 1 \/ i Loop Until i >= n sumD = s End Function Function sumF(n As Integer) As Single s = 0 For i = 1 To n s = s + 1 \/ i Next i sumF = s End Function Private Sub Form_...
求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为...
用Java编写一个程序,计算s=1+(1+2)+(1+2+3)+…+(1+2+3+4+5+…+100...
public class Sum { public static void main(String[] args) { int sum = 0;for(int i = 1; i <= 100; i++){ 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...
编写一个程序,输入正整数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);} ...
编程求1+(1+2)+(1+2+3)+……+(1+2+3…… +n), n的值由键盘输入。要求使...
include<stdio.h> int main(){ int i,n,m=0,s=0;printf("Please input the number:\\n");scanf("%d",&n);printf("n=%d\\n",n);for(i=1;i<n+1;i++){ m+=i;s+=m;} printf("s=%d\\n",s);return 0;}
4,利用For循环求S=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)的值.提示:本题...
include <iostream> 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);...
1+(1+2)+(1+2+3)+…+(1+2+...+n)等于多少
S=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)=1*(1+1)\/2+2*(1+2)\/2+3*(1+3)\/2+...+n*(1+n)\/2 =1\/2*{(1^2+2^2+3^2+...+n^2)+(1+2+3+...+n)} =1\/2*{n(n+1)(2n+1)\/6+n(n+1)\/2} =1\/2*n(n+1)(2n+1+3)\/6 =n(n+1...
编程求1+(1+2)+(1+2+3)+……+(1+2+3…… +n), n的值由键盘输入。要求使...
s = s + e;ans = ans + s;} ③ 根据数学公式优化,复杂度 O(1)令 a1 = 1, a2 = 1 + 2, a3 = 1+2+3 ... aN = 1+2+3...+n 根据等差数列前n项和公式可知, aN 的通项公式为 aN = (N^2 + N)\/2 题目所求即为 aN的前N项和 容易观察,前N项和为 (1^2 + 2^...