VB编程,谁帮帮忙,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/06/09 02:12:15
计算π的近似值,π的计算公式为:π=2*(2*2/1*3)*…(2*n)*(2*n)/(2n-1)(2n+1),要求,精度为0.000001,并输出n的大小,并注意表达式的书写,避免数据的"溢出"。

private sub command1_click()
dim TT as single,n as integer
TT=1
n=inputbox("")
for i = 1 to n
TT=(2*i)*(2*i)/(2*i-1)(2*i+1)*TT
next
?TT
end sub
TT的类型也可设置为double 但我认为SINGLE应该够了吧.

Private Sub command1_click()
Dim TT As Double, n As Integer
n = InputBox("你好", "标题")
TT = 1
For i = 1 To n
TT = (2 * i) * (2 * i) / (2 * i - 1) * (2 * i + 1) * TT
Next i
Print TT
End Sub