看vbs代码哪儿错了
来源:百度知道 编辑:UC知道 时间:2024/06/24 16:56:31
Dim e,a,b
Function f(x)
f=InputBox("输入函数","二分法求零点")
End Function
e=CInt(InputBox("输入精确度","二分法求零点")
Do
a=CInt(InputBox("输入区间一端","二分法求零点")
b=CInt(InputBox("输入区间另一端","二分法求零点")
If f(a)*f(b)>=0
Then msgbox"输入区间有误"
Else Exit Do
End If
Loop
Do
c=(a+b)/2
If f(c)=0
Then a=c Exit Do
ElseIf f(a)*f(c)<0
Then b=c
Else a=c
End If
If abs(a-b)<e
Then Exit Do
Loop
MsgBox a,64+4096,"二分法求零点"
Function f(x)
f=InputBox("输入函数","二分法求零点")
End Function
e=CInt(InputBox("输入精确度","二分法求零点")
Do
a=CInt(InputBox("输入区间一端","二分法求零点")
b=CInt(InputBox("输入区间另一端","二分法求零点")
If f(a)*f(b)>=0
Then msgbox"输入区间有误"
Else Exit Do
End If
Loop
Do
c=(a+b)/2
If f(c)=0
Then a=c Exit Do
ElseIf f(a)*f(c)<0
Then b=c
Else a=c
End If
If abs(a-b)<e
Then Exit Do
Loop
MsgBox a,64+4096,"二分法求零点"
,应该用英文的
e=CInt(InputBox("输入精确度","二分法求零点") ) 看清楚.你少了最后一个括号
If abs(a-b)<e
Then Exit Do
上面的and下面的
If f(c)=0
Then a=c Exit Do 这种格式写法.非常的错.希望你认真看书
if abs(a-b)<e then exit do
if f(c)=0 then
a=c
exit do
endif
例子:
if..条件..then
运算
elseif..条件..then
运算
endif
or
if..条件..then..运算..
or
if..条件..then
运算
endif