> 数学 >
求一元二次方程ax^2+bx+c=0的根.用VB语言怎么编?知道的都来帮帮忙,急.
人气:371 ℃ 时间:2019-10-19 14:51:21
解答
Private Sub Command1_Click()
Dim A As Single,B As Single,C As Single
Dim R1 As Single,R2 As Single
A = Val(Text1.Text)
B = Val(Text2.Text)
C = Val(Text3.Text)
If B ^ 2 - 4 * A * C < 0 Then
MsgBox "该方程无解."
ElseIf B ^ 2 - 4 * A * C = 0 Then
R1 = -B / 2 / A
MsgBox "该方程仅有一个根为" & R1 & "."
Else
R1 = (-B + Sqr(B ^ 2 - 4 * A * C)) / (2 * A)
R2 = (-B - Sqr(B ^ 2 - 4 * A * C)) / (2 * A)
MsgBox "该方程有两个根分别为" & R1 & "和" & R2 & "."
End If
End Sub
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版