用vb编写一个程序求一元二次方程ax2+bc+c=0的根

急!

用^表示幂,当b^2-4ac≥0时的根为.x=(-b±√(b^2-4ac))/(2a)称为一元二次方程的求根公式当b^2-4ac>0时,有两个不同的根当b^2-4ac=0时,有两个相同的根当b^2-4ac<0时,没有实数根.Private Sub Command1_Click()
Dim a, b, c
a = CDbl(InputBox("输入a值:"))
b = CDbl(InputBox("输入b值:"))
c = CDbl(InputBox("输入c值:"))
If b ^ 2 - 4 * a * c < 0 Then
Print "没有实根"
Else
Print "X1=" & (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
Print "X2=" & (-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
End IfEnd Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-08-16
Private Sub Command1_Click()
Me.Cls
On Error GoTo P:
Dim a As Single, b As Single, c As Single, x1 As Single, x2 As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)If (b * b - 4 * a * c) > 0 Then
x1 = (-b + Sqr((b ^ 2 - 4 * a * c))) / (2 * a)
x2 = (-b - Sqr((b ^ 2 - 4 * a * c))) / (2 * a)
Print "x1="; x1
Print "x2="; x2
ElseIf (b * b - 4 * a * c) = 0 Then
x = -b / 2 / a
Print "x="; x
Else
Print "无实数根。"
End If
P:
End Subxi 本来不想发源代码的。希望你能自己去图片上看····希望能对你有帮助

用VB编写求一元二次方程的代码是什么?
If a = 0 And b = 0 And c = 0 Then Print "x的值是全体实数."ElseIf a = 0 And b = 0 And c <> 0 Then Print "x的值不存在!"ElseIf a = 0 And b <> 0 Then Print "x1的值是"; (-c \/ b)ElseIf a <> 0 And (b ^ 2 - 4 * a * c) >= 0 Then gen =...

...b,c的值,编程求解一元二次方程ax^2+bx+c=0的根
界面的abc输入托文本框获取把Private Sub Command1_Click() 。Dim a As Single, b As Single, c As Single, t As Double a = Val (Text1.Text) b = Val (Text2.Text)。含义及特点:(1)一元二次方程的解(根)的意义:能使一元二次方程左右两边相等的未知数的值称为一元二次方程...

用vb做:输入一元二次方程ax^2+bx+c=0的系数abc,计算并输出一元二次方 ...
a =val(inputbox("请输入系数a"))b =val(inputbox("请输入系数b"))c =val(inputbox("请输入系数c"))d=b^2-4*a*c if d>0 then x1=(-b+sqr(d))\/2 x2=(-b-sqr(d))\/2 elseif d=0 then x1=-b\/2 x2=x1 else msgbox "方程无实根!"end if ...

vb 程序 输入一元二次方程ax2+bx+c=0的系数a,b,c,计算并输出一元二...
Private Sub Command1_Click()Dim a As Integer, b As Integer, c As Integer Dim s As Single, x1 As Single, x2 As Single a = Text1.Text b = Text2.Text c = Text3.Text s = Sqr(b * b - 4 * a * c)If s = 0 Then x1 = x2 = -b \/ (2 * a)Else If s > ...

大学vb,设计应用程序求解一元二次方程ax^2+bx+c=0
List1.AddItem a & "*" & x & "^2+" & b & "*" & x & "+" & c & "=0" List1.AddItem "" End If End If Next x Next c Next b Next a使用穷举法计算

一元二次方程计算机解
在VB编程中,可以使用以下代码来实现一元二次方程的求解。这个代码适用于一般形式的一元二次方程 ax^2 + bx + c = 0,并会以对话框的形式显示解的结果。首先,需要定义变量a、b和c,以及可能的解x1和x2,例如:vbDim a As Double, b As Double, c As Double, x1 As Double, x2 As ...

VB6.0实现一元二次方程的求解
一元二次方程的基本形式是:ax^2+bx+c=0,其中a不等于0。 程序中的a、b、c分别与上式中的系数对应,X1、X2表示两个根。 程序的思路是:先判断方程有无实数解(b^2-4ac大于等于0),有的话就用求根公式进行求解。双击窗体Form1,进入代码编辑窗口,在 通用段对变量进行定义。 Dim a As ...

如何利用VB解一元二次方程
你知道一元二次方程求根公式吗?直接用就行了 方程aX^2+bX+c=0 解为 X1 = (-b + Sqr(b * b - 4 * a * c)) \/ 2.0 * a X2 = (-b - Sqr(b * b - 4 * a * c)) \/ 2.0 * a 其实应该先判断一下b * b - 4 * a * c是否小于零,但你又说不用IF 等复杂结构...

vb程序改错 求解一元二次方程(ax^2+bx+c=0)的程序
("c=")第二个:x1 = (-b - d)\/ (2 a)应该是 x2 = (-b - d)\/ (2 a)另外d有开方过程 ,最好设为 double而不是 integer 最好再加个判断判别式的过程:Private Sub Command1_Click()Dim a As Integer,b As Integer,c As Integer,d As Double Dim x1 As Single,x2 As Single...

用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...

相似回答