vb 程序 输入一元二次方程ax2+bx+c=0的系数a,b,c,计算并输出一元二次方程的两个根x1,x2。 求解
展开全部
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 > 0 Then
x1 = (-b + s) / (2 * a)
x2 = (-b - s) / (2 * a)
Else
x1 = -b / (2 * a) + s & "i"
x2 = -b / (2 * a) - s & "i"
End If
End If
End Sub
可以不要那个结束按钮。
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 > 0 Then
x1 = (-b + s) / (2 * a)
x2 = (-b - s) / (2 * a)
Else
x1 = -b / (2 * a) + s & "i"
x2 = -b / (2 * a) - s & "i"
End If
End If
End Sub
可以不要那个结束按钮。
展开全部
这个问题是很简单的啊。
private sub command1_click()
dim a,b,c as sigle
a=val(text1.text )
b=val(text2.text )
c=val(text3.text )
if b^2-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
else
x1= (-b-sqr( abs(b^2-4*a*c) ))/2*a & i
x2=(-b+sqr( abs(b^2-4*a*c) ))/2*a & i
end if
end sub
private sub command1_click()
dim a,b,c as sigle
a=val(text1.text )
b=val(text2.text )
c=val(text3.text )
if b^2-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
else
x1= (-b-sqr( abs(b^2-4*a*c) ))/2*a & i
x2=(-b+sqr( abs(b^2-4*a*c) ))/2*a & i
end if
end sub
追问
前两句有问题·····
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询