数学
VB程序设计问题,求解答 用下列多项式可求得π的近似值:计算当n不超过300时π的近似值.程序中有3个错误,请调试改正.Private Sub Command3Click()'调试改错题3按钮 Dim pi#, t#, n#, s% pi = 0 n = 1 s = 1 Do n = n + 2 t = 1 / n s = -1

2019-05-30

VB程序设计问题,求解答 用下列多项式可求得π的近似值:
计算当n不超过300时π的近似值.程序中有3个错误,请调试改正.
Private Sub Command3_Click()
'调试改错题3按钮
Dim pi#, t#, n#, s%
pi = 0
n = 1
s = 1
Do
n = n + 2
t = 1 / n
s = -1 '用于分式正负符号转换
pi = pi + s * t
Loop While n
优质解答
Dim pi#, t#, n#, s%

这样声明不太方便,现在一般都用as来声明
Label3.Caption = "当n=" & n - 2 & "时," & " pi= " + pi

这句类型不匹配,改成
Label3.Caption = "当n=" & n - 2 & "时," & " pi= " & pi
其它的程序可以运行,显示结果为
当n=299时, pi= -9.9615833804551
Dim pi#, t#, n#, s%

这样声明不太方便,现在一般都用as来声明
Label3.Caption = "当n=" & n - 2 & "时," & " pi= " + pi

这句类型不匹配,改成
Label3.Caption = "当n=" & n - 2 & "时," & " pi= " & pi
其它的程序可以运行,显示结果为
当n=299时, pi= -9.9615833804551
相关问答