不是要求所得的值,是要怎么编写才能输出过程。就是式子
例如输入3
那么输出1+(1+2)+(1+2+3)
以此类推。
一下是得出答案的代码。
Dim n As Integer, s As Integer, i As Integer, j As Integer
n = Val(InputBox("请输入一个数:"))
For i = 1 To n
For j = 1 To i
s = s + j
Next j
Next i
t1.Text = s
囧~~
我是需要在计算的同时输出
1+(1+2)+(1+2+3)...(1+2+...n)
求在VB中如何输出1+(1+2)+(1+2+3)...(1+2+...n)的式子(在线等)
Dim n As Integer, s As Integer, i As Integer, j As Integer a = ""b = ""n = Val(InputBox("请输入一个数:"))For i = 1 To n For j = 1 To i If j = 1 Then a = 1 Else a = a & "+" & j s = s + j Next j If b = "" Then b = a Else b = b...
s=1+(1+2)+(1+2+3)+...+(1+2+3+...n)的vb的循环结构编程
参考代码:n = InputBox("输入n")For i = 1 To n For j = 1 To i Sum = Sum + j NextNextMsgBox "s=" & Sum
vb编程:计算1+(1+2)+(1+2+3)+...+(1+2+3+...+n)
Private Sub Form_Click()Dim I as Integer, S as Long, Sum as Long N=10 For i=1 to N S=S+I Sum=Sum+S Next Print Sum 'N=10的结果 End Sub
用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_...
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为结果 ...
vb程序设计,一道题s=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)输入n
望采纳。。。
编程:从键盘输入正整数n,输出1+(1+2)+(1+2+3)+...+(1+2+3+...+n...
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)...你可以...
vb采用递推法计算s=1+(1+2)+(1+2+3)+…+(1+2+3+…+10)
n=10 for j = 1 to n for i = 1 to j s=s+i next next msgbox s
编程实现求Sum=1+(1+2)+(1+2+3)+(1+2+3+4)+ …… +(1+2+3+4+ … +...
isum=0 jsum=0 read(*,*) n do i=1,n do j=1,i jsum=jsum+j enddo isum=isum+jsum jsum=0 enddo print*,isum end 这是fortran程序,自己改成vb语法或其他你自己需要的语法即可
编程实现求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