vb中怎样编写“1+(1+2)+(1+2+3)+(1++2+3+4)+。。。。。。”程序

如题所述

Private Sub Command1_Click()
Dim i, j, n, sum1, sum2 As Integer
n = InputBox("请输入n")
sum1 = 0
sum2 = 1
For i = 1 To n
For j = 1 To i
sum1 = sum1 + j
Next j
sum2 = sum2 + sum1
Next i
End Sub

sum2为结果
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-06-05
Private Sub command1_click()
n = InputBox("请输入正整数n的值")
y = 0
For i = 1 To n
s = 0
For j = 1 To i
s = s + j
Next j
y = y + s
Next i
Print y;
End Sub
第2个回答  2012-06-05
Dim N&, i&, Total&
Private Sub Command1_Click()
N = InputBox("请输入n")
Call SumN(N)
Print Total
End Sub
Sub SumN(S&)
For i = 1 To S
Total = Total + i
Next
If S > 1 Then Call SumN(S - 1)
End Sub
第3个回答  2012-06-05
楼上正解

vb中怎样编写“1+(1+2)+(1+2+3)+(1++2+3+4)+。。。”程序
Private Sub Command1_Click()Dim i, j, n, sum1, sum2 As Integer n = InputBox("请输入n")sum1 = 0 sum2 = 1 For i = 1 To n For j = 1 To i sum1 = sum1 + j Next j sum2 = sum2 + sum1 Next i End Sub sum2为结果 ...

编写一个程序,计算下式之和: 1+(1+2)+(1+2+3)+(1+2+3+4)+……+(1+2+
int main(int argc, char** argv){ int num = 0; char *temp[100];int sum = 0, tmp = 0, pos = 0;do{ printf("请输入 N 值:");scanf("%d",&num) || scanf("%s", (char*)temp);if(num >= 1)break;}while(1);while(pos < num){ tmp += ++pos;sum += tmp;} ...

用while和do while语句编写程序s=1+(1+2)+(1+2+3)+……+(1+2+3+4+...
void main(){ int n,s,t,k;scanf("%d",&n);s=t=0; k=1; while ( k<=n ) { t+=k; s+=t; k++; } printf("%d\\n",s);s=t=0; k=1; do { t+=k; s+=t; k++; } while ( k<=n ); printf("%d\\n",s);} ...

编程实现求Sum=1+(1+2)+(1+2+3)+(1+2+3+4)+ …… +(1+2+3+4+ … +...
这是fortran程序,自己改成vb语法或其他你自己需要的语法即可

用while循环如何编写求1+(1+2)+(1+2+3)+………+(1+2+3+4+……+100...
首先根据高效算法 1+2+...n = n*(n+1) \/2 #include"stdio.h"#include"stdlib.h"int fn(int n){ return n*(n+1) \/2}void main(){ int sum = 0; int j = 0; for(j=1; j<=100;j++) { sum += fn(j); }} ...

用while循环如何编写求1+(1+2)+(1+2+3)+………+(1+2+3+4+……+100...
include<stdio.h> main(){ int i=1,n=1,sum=0;while(i<=100){ n=1;while(n<=i){ sum=sum+n;n++;} i++;} printf("%d",sum);}

用C语言编写程序,求s=1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+…n)。
void main(){ int n,i,j;long s=0;printf("Please input n:");scanf("%d",&n);for(i=1;i<=n;i++)for(j=1;j<=i;j++){ s+=j;} printf("s=1+(1+2)+(1+2+3)+(1+2+3+4)+(1+2+3+4+…+n)=%ld",s);} 利用for循环,根据式子的特性进行相加,得出最终结果。

从键盘输入一个数n(整数),计算1+(1+2)+(1+2+3)+...+(1+2+3+4+5
sum+=i;return sum;} void main(){ int i,n,sum=0;scanf("%d",&n);for(i=1;i<=n;++i)sum+=sum_n(i);printf("sum = %d\\n",sum);}这样只是最简单的一种,效率不高,实际情况做的时候通常是把表达式整理成一个多项表达式来直接做运算,比如说你的那几个1+(1+2)...你可以...

用函数实现求sum=1+(1+2)+(1+2+3)+(1+2+3+4)+...+(1+2
include <stdio.h>int sumInAll(int n){ int ret=0,sum=0; for (int i=1;i<=n;i++){ sum+=i;ret+=sum; } return(ret);}int main() { int n; scanf("%d", &n); printf("%d", sumInAll(n)); return 0;} ...

求1+(1+2)+(1+2+3) +(1+2+3+4)+…+(1+2+…+n) 。要求:设计一个函数,专 ...
循环加花括号

相似回答