vb题:利用级数π^2/6=1+1/2^2+1/3^2+...+1/n^2求当n=5、n=10、n=20...
发布网友
发布时间:2024-10-07 17:06
我来回答
共1个回答
热心网友
时间:2024-10-21 13:30
Private Sub Command1_Click()
Print "n=5时,PI的近似值为"; PI(5)
Print "n=10时,PI的近似值为"; PI(10)
Print "n=20时,PI的近似值为"; PI(20)
End Sub
Function PI(m As Integer) As Double
For i = 1 To m
n = 1 / (i * i) + n
Next
n = Round(Sqr(n * 6), 5)
PI = n
End Function