vb题:利用级数π^2⼀6=1+1⼀2^2+1⼀3^2+........+1⼀n^2求当n=5、n=10、n=20时π的近似值

2025-01-02 12:59:47
推荐回答(2个)
回答1:

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

回答2:

3.14159