如何用VB求一元二次方程的虚数解(一定是虚数解).
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/27 02:49:56
如何用VB求一元二次方程的虚数解(一定是虚数解).
如何用VB求一元二次方程的虚数解(一定是虚数解).
如何用VB求一元二次方程的虚数解(一定是虚数解).
解一元二次方程的Vb程序:
在窗体上画一个命令按钮,输入下列代码,运行后可在窗体打印结果.
Private Sub Command1_Click()
dim a as double,b as double ,c as double,x as string
a=inputbox("请输入系数a:")
b=inputbox("请输入系数b:")
c=inputbox("请输入系数c:")
x=QuarEquation(a,b,c)
print x
end sub
printe function QuarEquation(byval a as double,byval b as double,byval c as double) as string
dim a as double,b as double ,c as double,P as double
dim xr as double ,xi as double ,x as string,xp as double
dim x1 as string,x2 as string,hh as string
hh=chr(13)+chr(10)
xr=-b/2
p=b^2-4*a*c
select case p
case is >0
xp=sqr(P)/2
x1=xr+xp
x2=xr-xp
x="x1=" & x1 & ";" & hh "x2=" & x2
QuarEquation=x
case is = 0
x="x1=x2=" &xr
QuarEquation=x
case is