问题描述:
vb编写程序,利用下面的公式计算cosx的近似值
cosx=1-x^2/2!+x^4/4!.+x^(2n)/(2n)!我写的代码:
Private Sub Command1_Click()
Dim x As Single,t As Single,s As Single,n As Integer
x = Val(Text1.Text)
s = 1:t = 1:n = 1
Do
t = (-1) * t * (x ^ (2 * n)) / ((2 * n - 1) * (2 * n))
s = t + s
n = n + 1
Loop Until t = -10 ^ (-7)
Text2.Text = s
但是“溢出”,= (-1) * t * (x ^ (2 * n)) / ((2 * n - 1) * (2 * n)),但是我不明白为什么
cosx=1-x^2/2!+x^4/4!.+x^(2n)/(2n)!我写的代码:
Private Sub Command1_Click()
Dim x As Single,t As Single,s As Single,n As Integer
x = Val(Text1.Text)
s = 1:t = 1:n = 1
Do
t = (-1) * t * (x ^ (2 * n)) / ((2 * n - 1) * (2 * n))
s = t + s
n = n + 1
Loop Until t = -10 ^ (-7)
Text2.Text = s
但是“溢出”,= (-1) * t * (x ^ (2 * n)) / ((2 * n - 1) * (2 * n)),但是我不明白为什么
问题解答:
我来补答展开全文阅读