求一元二次方程ax^2+bx+c=0的根.用VB语言怎么编?知道的都来帮帮忙,急.
题目
求一元二次方程ax^2+bx+c=0的根.用VB语言怎么编?知道的都来帮帮忙,急.
答案
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
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
最新试题
热门考点