早教吧作业答案频道 -->数学-->
vb程序改错 求解一元二次方程(ax^2+bx+c=0)的程序求解一元二次方程(ax^2+bx+c=0)的程序Private Sub Command1_Click()Dim a As Integer,b As Integer,c As Integer,d As IntegerDim x1 As Single,x2 As SingleInputBox ("a=")InputBox
题目详情
vb程序改错 求解一元二次方程(ax^2+bx+c=0)的程序
求解一元二次方程(ax^2+bx+c=0)的程序
Private Sub Command1_Click()
Dim a As Integer,b As Integer,c As Integer,d As Integer
Dim x1 As Single,x2 As Single
InputBox ("a=")
InputBox ("b=")
InputBox ("c=")
d = Sqr(b * b - 4 * a * c)
x1 = (-b + d) / (2 * a)
x1 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
请问错在哪里
求解一元二次方程(ax^2+bx+c=0)的程序
Private Sub Command1_Click()
Dim a As Integer,b As Integer,c As Integer,d As Integer
Dim x1 As Single,x2 As Single
InputBox ("a=")
InputBox ("b=")
InputBox ("c=")
d = Sqr(b * b - 4 * a * c)
x1 = (-b + d) / (2 * a)
x1 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
请问错在哪里
▼优质解答
答案和解析
两处错误,第一个,没有赋值过程 ,应该改为:
a=InputBox ("a=")
b=InputBox ("b=")
c=InputBox ("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
a = InputBox("a=")
b = InputBox("b=")
c = InputBox("c=")
d = b * b - 4 * a * c
If d < 0 Then
MsgBox "判别式小于0"
Exit Sub
End If
d = Sqr(d)
x1 = (-b + d) / (2 * a)
x2 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
a=InputBox ("a=")
b=InputBox ("b=")
c=InputBox ("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
a = InputBox("a=")
b = InputBox("b=")
c = InputBox("c=")
d = b * b - 4 * a * c
If d < 0 Then
MsgBox "判别式小于0"
Exit Sub
End If
d = Sqr(d)
x1 = (-b + d) / (2 * a)
x2 = (-b - d) / (2 * a)
Print "x1="; x1,"x2="; x2
End Sub
看了 vb程序改错 求解一元二次方...的网友还看了以下:
一元二次方程试题1.已知a是关于x的一元二次方程x2-3x+m=0的一个根,-a是关于x的一元二次 2020-04-05 …
关于的一元二次方程x2+2x+k+1=0的实数解是x1和x2. (1)求k的取值范围; (2)如果 2020-05-16 …
已知二次此函数y=x2(指平方)+bx+c的图像与x轴的两个交点的横坐标分别为x1,x2,一元二次 2020-05-16 …
1.已知一元二次方程(m+1)x2-x+m2-3m-3=0有一个根是1,则另一根为2.若x1=根号 2020-06-27 …
已知二次函数y=x2+bx+c的图象与x轴的两个交点的横坐标分别为x1、x2,一元二次方程x2+b 2020-07-16 …
将关于x的一元二次方程x2+bx+c=0变形为x2=-bx-c,就可得x2表示为关于x的一次多项式 2020-08-03 …
将关于x的一元二次方程x2次+px+q=0变形为x2次=-px-q,就可以将x2次表示委关于x的一 2020-08-03 …
1.x2次+y3次-2x-6y=-10,则x2011次*y2次的值为?2.x2次-ax-1可分解为( 2020-11-01 …
我们已探究过一元二次方程的根与系数有如下关系:方程ax2+bx+c=0(a≠0)的两个根是x1,x2 2020-11-07 …
若x2+xy-2y2=0,则(x2+3xy+y2)/(x2+y2)=?字母后面的数字代表几次方,如x 2021-01-12 …