十万火急!!!请VB高手帮我解答此程序改错题!每个FOUND的下一行都有错误,请改正。明天就考试了,着急!
【程序改错】'------------------------------------------------'题目:已知自然对数的底数e的级数表示如下:'e=1+1/1...
【程序改错】
'------------------------------------------------
'题目:已知自然对数的底数e的级数表示如下:
' e=1+1/1!+1/2!+1/3!+......+1/n!+.....
' 本程序利用函数过程fact()求e,其中绝对值小于
' 1E-8的项被忽略。
'------------------------------------------------
Option Explicit
Private Function fact(m As Integer) As Single
Dim x As Single, i As Integer
x = 1
For i = 1 To m
'**********FOUND**********
x = i
Next i
fact = x
End Function
Private Sub Form_Click()
Dim e As Single, item As Single
Dim n As Integer
e = 1
'**********FOUND**********
n = -1
Do
n = n + 1
item = 1 / fact(n)
e = e + item
'**********FOUND**********
Loop While item >= 0.01
Form1.Print "e="; e
End Sub 展开
'------------------------------------------------
'题目:已知自然对数的底数e的级数表示如下:
' e=1+1/1!+1/2!+1/3!+......+1/n!+.....
' 本程序利用函数过程fact()求e,其中绝对值小于
' 1E-8的项被忽略。
'------------------------------------------------
Option Explicit
Private Function fact(m As Integer) As Single
Dim x As Single, i As Integer
x = 1
For i = 1 To m
'**********FOUND**********
x = i
Next i
fact = x
End Function
Private Sub Form_Click()
Dim e As Single, item As Single
Dim n As Integer
e = 1
'**********FOUND**********
n = -1
Do
n = n + 1
item = 1 / fact(n)
e = e + item
'**********FOUND**********
Loop While item >= 0.01
Form1.Print "e="; e
End Sub 展开
3个回答
展开全部
x = 1
For i = 1 To m
'**********FOUND**********
x = i
x被重定义,此循环不会结束
-------------------------------------
fact(n)要求n为非负数
你的n一开始就是-1
那么在+1后,为0
那么1/0是无理数,所以会错
-------------
因为 item = 1 / fact(n)这儿就错了
所以
'**********FOUND**********
Loop While item >= 0.01
不成立
For i = 1 To m
'**********FOUND**********
x = i
x被重定义,此循环不会结束
-------------------------------------
fact(n)要求n为非负数
你的n一开始就是-1
那么在+1后,为0
那么1/0是无理数,所以会错
-------------
因为 item = 1 / fact(n)这儿就错了
所以
'**********FOUND**********
Loop While item >= 0.01
不成立
追问
请你将正确答案填上好吗?我需要的是答案!不理解就背下来!
追答
x = 1
For i = 1 To m
'**********FOUND**********
Next i
----------------
'**********FOUND**********
n = 0
Do
n = n + 1
item = 1 / fact(n)
e = e + item
---------------------------------
'**********FOUND**********
Loop While item >= 0.01
'这个不需要改,它的报错是因为上面的n错误,导致这儿无限循环
展开全部
Option Explicit
Private Function fact(m As Integer) As Single
Dim x As Single, i As Integer
x = 1
For i = 1 To m
'**********FOUND**********
x = x * i
Next i
fact = x
End Function
Private Sub Form_Click()
Dim e As Single, item As Single
Dim n As Integer
e = 1
'**********FOUND**********
n = 0
Do
n = n + 1
item = 1 / fact(n)
e = e + item
'**********FOUND**********
Loop While item >= 0.00000001
Form1.Print "e="; e
End Sub
Private Function fact(m As Integer) As Single
Dim x As Single, i As Integer
x = 1
For i = 1 To m
'**********FOUND**********
x = x * i
Next i
fact = x
End Function
Private Sub Form_Click()
Dim e As Single, item As Single
Dim n As Integer
e = 1
'**********FOUND**********
n = 0
Do
n = n + 1
item = 1 / fact(n)
e = e + item
'**********FOUND**********
Loop While item >= 0.00000001
Form1.Print "e="; e
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Click()
Dim n As Integer, k As Integer, i As Integer, swit As Integer
For n = 101 To 300 Step 2
k = Int(Sqr(n))
i = 2
'**********FOUND**********
swit = 0
'**********FOUND**********
While i <= k
If n Mod i = 0 Then
swit = 1
i = k + 1
Else
'**********FOUND**********
i = i + 1
End If
Wend
If swit = 0 Then
Print n;
End If
Next n
End Sub
Dim n As Integer, k As Integer, i As Integer, swit As Integer
For n = 101 To 300 Step 2
k = Int(Sqr(n))
i = 2
'**********FOUND**********
swit = 0
'**********FOUND**********
While i <= k
If n Mod i = 0 Then
swit = 1
i = k + 1
Else
'**********FOUND**********
i = i + 1
End If
Wend
If swit = 0 Then
Print n;
End If
Next n
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询