vb中编写过程,计算π的近似值
问题描述:
vb中编写过程,计算π的近似值
公式π/4=1-1/3+1/5-1/7+……+(-1)^(n-1)*(1/(2*n-1))
答
Dim sign As Integer,a As Long,pi As Double
sign = -1
For i = 1 To 100000
a = 2 * i - 1
sign = -1 * sign
pi = pi + (1 / a) * sign
Next
pi = pi * 4
MsgBox pi