请vb高手帮忙。vb程序填空。编写计算s=1-1/3!+1/5!-1/7!+......+(-1)^n-1/(2n-1).程序如下。
PrivateSubCommand1_Click()Dimi,nAsIntegerDimj,sAsIntegerj=1s=1n=Val(Text1.Text)Fori=2...
Private Sub Command1_Click()
Dim i, n As Integer
Dim j, s As Integer
j = 1
s = 1
n = Val(Text1.Text)
For i = 2 To n
j=____________________
s=_____________________
Next i
Text2.Text = Str(s)
End Sub 展开
Dim i, n As Integer
Dim j, s As Integer
j = 1
s = 1
n = Val(Text1.Text)
For i = 2 To n
j=____________________
s=_____________________
Next i
Text2.Text = Str(s)
End Sub 展开
展开全部
如果是考试的话,填
j=j*(2*i-2)*(2*i-1)
s=s+(-1)^(i-1)*(1/j)
但是这一题目本身有问题,变量变义出错,会导致结果一直是1,然后在正式计算的时候还会遇到数据溢出,应该是
Private Sub Command1_Click()
Dim i, n As Integer
Dim j As Variant
Dim s As Double
j = 1
s = 1
n = Val(Text1.Text)
For i = 2 To n
j=j*(2*i-2)*(2*i-1)
s=s+(-1)^(i-1)*(1/j)
Next i
Text2.Text = Str(s)
End Sub
这样大约在text1填80多的时候数据才会溢出(text1为80的时候最终为2.946E+282)
j=j*(2*i-2)*(2*i-1)
s=s+(-1)^(i-1)*(1/j)
但是这一题目本身有问题,变量变义出错,会导致结果一直是1,然后在正式计算的时候还会遇到数据溢出,应该是
Private Sub Command1_Click()
Dim i, n As Integer
Dim j As Variant
Dim s As Double
j = 1
s = 1
n = Val(Text1.Text)
For i = 2 To n
j=j*(2*i-2)*(2*i-1)
s=s+(-1)^(i-1)*(1/j)
Next i
Text2.Text = Str(s)
End Sub
这样大约在text1填80多的时候数据才会溢出(text1为80的时候最终为2.946E+282)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询