一元二次方程ax^2+bx+c=0的解x VB怎么写?
问题描述:
一元二次方程ax^2+bx+c=0的解x VB怎么写?
答
Private Sub Command1_Click()
Dim a As Integer,b As Integer,c As Integer
Dim m As Integer,x1 As Integer,x2 As Integer
a = Text1.Text
b = Text2.Text
c = Text3.Text
m = b ^ 2 - 4 * a * c
If a = 0 Then
Print wrong
Else
Select Case m
Case Is > 0
x1 = (-b + Sqr(m) / (2 * a))
x2 = (-b - Sqr(m) / (2 * a))
Print "不相等的两根 x1=" & x1 & ",x2=" & x2
Case 0
x1 = x2 = (-b / (2 * a))
Print "相等的两根 x1=x2 =" & x1
Case Is Print "No Real"
End Select
End If
End Sub