请教VB答案,求VB强人

来源:百度知道 编辑:UC知道 时间:2024/06/05 11:47:48
编写一个Sub过程,计算(0+1+2+3+…+2 I -1)/2I!调用该过程编程序求:1/2!+(1+2+3)/4!+(1+2+3+4+5)/6!+… (1+2+3+…+2 I -1)/I!+ … (1+2+3+…+2n-1)/2n!,n(0<n<200)由用户用InputBox函数输入,并要求:
1.给出界面设计,绘图表示;
2.程序完善,或有错误处理程序;
3.计算结果保留6位小数。
这是我编的,不过n只能取到85,不能大于,不然显示错误:
谢谢帮助

Dim n As Integer, s As Double
Dim i As Integer, j As Integer, k As Integer
Option Base 1

Private Sub Command1_Click()

n = InputBox("输入n(0<n<200)", "输入数据")

Call calculate

Print Format(s, "0.000000")

End Sub
Private Sub calculate()

ReDim h(n) As Double, c(n) As Double

h(1) = 1
For i = 2 To n
h(i) = h(i - 1) + (2 * (i - 1)) + (2 * i - 1)
Next i

c(1) = 2
For j = 2 To n
c(j) = c(j - 1) * (2 * j - 1) * (2 * j)
Next j

s = 0
For k = 1 To n
s = s + h(k) / c(k)
Next k

End Sub

Private Sub Command2_Cl

用递归。

你这样问可不是什么请教,你只是把别人当做免费的劳力。

只能到85!,这是电脑的极限,我编的,一个Command1,一个picture,图形你没说清楚要什么变量。

Dim n As String
Dim a, c, e, j As Integer
Dim d As Double
Dim b As Boolean
Dim f, g, h As Double
Dim i As Long
Private Sub Command1_Click()
Picture1.Scale (0, 3)-(80, 0)
Picture1.Cls
h = 0
g = 0
j = 0
b = False
n = InputBox("数字", "n", "")
If n = "" Then
b = True
Else
For a = 1 To Len(n)
If Asc(Mid(n, a, 1)) >= 47 And Asc(Mid(n, a, 1)) <= 58 Then

Else
b = True
End If
Next a
End If
If b Then
Picture1.Cls
Else

For a = 1 To 2 * n
d = 1
e = 0
For c = 2 To a
d = d * c

e = e + c - 1

Next c
f = e / d
g = g + f
Picture1.Line (j, h)-(a, g), RGB(250, 0, 250)
h = g
j = a
Next a

i = g * 1000000
Form1.Cls