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

如题所述

第1个回答  2012-06-05
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追问

好像不能运行

追答

Private Sub Command1_Click()
Dim i, j, n, sum As Integer
n = InputBox("请输入n")
sum1 = 0
For i = 1 To n
For j = 1 To i
sum = sum + j
Next j
Next i
Print sum
End Sub
是这个,原来那个有点问题。

第2个回答  2012-06-09
Private Sub Command1_Click()
Dim i, j, n As Integer, s As Single
s = 0
n = Val(InputBox("请输入一个正整数:"))
For i = 1 To n
For j = 1 To i
s = s + j
Next j, i
Print s

End Sub本回答被网友采纳

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) 。要求:设计一个函数,专 ...
循环加花括号

相似回答
大家正在搜