VB 求前N项和 急
求下面数列所得前N项和保留4位小数数列是1/(1+2)1/(1+2+3)1/(1+2+3+4)求下面数列所得的得数保留4位小数数列是1/(1+2)1/(1+2+3)1/(...
求下面数列所得前N项和保留4位小数 数列是1/(1+2)1/(1+2+3)1/(1+2+3+4)
求下面数列所得的得数保留4位小数数列是1/(1+2)1/(1+2+3)1/(1+2+3+4)后面以此类推 展开
求下面数列所得的得数保留4位小数数列是1/(1+2)1/(1+2+3)1/(1+2+3+4)后面以此类推 展开
3个回答
展开全部
Function sum(ByVal n As Integer) As String
Dim i As Integer
Dim a As Double
Dim b As Integer
b = 1
If n < 2 Then
sum = 1
Exit Function
End If
For i = 2 To n
b = b + i
a = a + CDbl(1 / b)
Next i
sum = Format(a, "#.0000")
End Function
Private Sub Command1_Click()
MsgBox sum(6)
End Sub
参考这个,希望可以帮到你
展开全部
Private Sub Command1_Click()
Dim n As Integer, i As Integer, mysum As Single, p As Single
n = Val(InputBox("请输入一个数:"))
For i = 1 To n
mysum = mysum + i
p = Format((1 / (mysum + i + 1)), "0.0000")
Next i
MsgBox p
End Sub
Dim n As Integer, i As Integer, mysum As Single, p As Single
n = Val(InputBox("请输入一个数:"))
For i = 1 To n
mysum = mysum + i
p = Format((1 / (mysum + i + 1)), "0.0000")
Next i
MsgBox p
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function sum(num as integer)
sum=(1+num)*num/2
end function
private sub command1_click()
dim i as integer
dim s as double
s=0
for i=1 to n
s=s+1/sum(i+1)
next
msgbox round(s,4)
end sub
private sub command2_click()
dim i as integer
for i=1 to n
msgbox round(1/sum(i+1),4)
end sub
sum=(1+num)*num/2
end function
private sub command1_click()
dim i as integer
dim s as double
s=0
for i=1 to n
s=s+1/sum(i+1)
next
msgbox round(s,4)
end sub
private sub command2_click()
dim i as integer
for i=1 to n
msgbox round(1/sum(i+1),4)
end sub
追问
这个是VB么,我不懂,帮别人问的。我打的/是分之哦
追答
是vb啊。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询