怎么用VB计算圆周率

2025-01-02 17:30:01
推荐回答(2个)
回答1:

圆周率π,在vb
编程中,你用健盘是输入不到这个值的,你得用一个常数来定义它的值,如计算圆的体积v=4/3*π*r*r*r,且设r为2,可以用下面的程序代码来编写:
(方法一):let
p=3.141592
let
r=2
let
v=4/3*p*r*r*r
print
v
end
(方法二):const
p=3.141592
let
r=2
let
v=4/3*p*r^3
print
v
end
说明:第二个是利用符号常量来代表∏,也就是用函数const定义了p的值,p的值变成了常量,此时在程序中不允许再赋新值

回答2:

Dim I%, J%
Dim Eps!
Dim Pi, Term As Double
Eps = 0.0000001
Term = 1
I = 1
J = 3
Pi = 0
Do While Term > Eps
Pi = Pi + Term
Term = Term * (I / J)
I = I + 1
J = J + 2
Loop