用VB解一元二次方程ax^2+bx+c=0的流程图

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/08 05:49:53

用VB解一元二次方程ax^2+bx+c=0的流程图
用VB解一元二次方程ax^2+bx+c=0的流程图

用VB解一元二次方程ax^2+bx+c=0的流程图
在窗体上分别放三个文本框用于输入a,b,c的值,再放一个按钮用于求解
private sub command1_click()
dim x as double,x1 as double,x2 as double,a1 as double,a2 as double
a =val(text1.text)
b =val(text2.text)
c =val(text3.text)
cls
currentx=600
currenty=1100
if a =0 then
if b =0 then
msgbox "系数为0,请重新输入!"
text1.setfocus
text1.selstart=0
text1.sellength=len(text1.text)
else
x=-c/b
print "x=";format(x,"0.000")
end if
exit sub
end if
dim n as double
n=b^2-4*a*c
select case n
case 0
print "x1=x2=";format(-b/(2*a),"0.000")
case is >0
x1=(-b+sqr(n)/(2*a)
x2=(-b-sqr(n)/(2*a)
print "x1=";format(x1,"0.000")
currentx=600
currenty=1300
print "x2=";format(x2,"0.000")
case is