早教吧 育儿知识 作业答案 考试题库 百科 知识分享

编写程序求1+(1+2)+(1+2+3)+……前100项的和……vb用vb最好完整一点PrivateSubCommand1Click()Dimj,n,sAsIntegern=100s=0Forj=1Tons=s+f(j)NextPrint"S=1+(1+2)+(1+2+3)+…+(1+2+3+4+…

题目详情
编写程序 求1+(1+2)+(1+2+3)+……前100项的和……vb
用vb 最好完整一点
Private Sub Command1_Click()
Dim j,n,s As Integer
n = 100
s = 0
For j = 1 To n
s = s + f(j)
Next
Print "S=1+(1+2)+(1+2+3)+…+(1+2+3+4+…+100)=",s
End Sub
Function f(Bybal n As Integer) As Integer
Dim i,t As Integer
s = 0
For i = 1 To n
t = t + i
Next
f = t
End Function------这个是网络找的,输入vb一直有错
▼优质解答
答案和解析
Private Sub Form_Click()
Dim i As Long,S As Long
For i = 1 To 100
S = S + CalcSum(i)
Next
Print S
End Sub
Function CalcSum(N As Long)
If N = 1 Then
CalcSum = 1
Else
CalcSum = CalcSum(N - 1) + N
End If
End Function