“求一元二次方程的根”的vb代码怎么写,跪求,谢谢
3个回答
展开全部
Private Sub Command1_Click()
a = Val(Text1) '文本框里的值取出来
b = Val(Text2) 旅御 '分别存到三个变量里,做方程的系数
c = Val(Text3)
If a <> 0 Then '首先判断第一个系数不为0 的情况
dt = b ^ 2 - 4 * a * c '公式中用到的表达式暂存
r = -b / (2 * a)
If dt > 0 Then '这种情况时用公式求方程的根
s = Sqr(dt) / (2 * a)
q1 = "x1=" & Format(r + s, "#.00")
q2 = "x2=" & Format(r - s, "#.00")
Label1.Caption = "方程的根分别是:" & q1 & " 和 " & q2 '输出方程的两野桥个根
ElseIf dt = 0 Then
Label1.Caption = "x1=x2=" & Format(r, "#.00") '两个相等根的输出
Else
Label1.Caption = "无实根" '没有实根
End If
ElseIf b <> 0 Then '一元一次方程的情况处理
y = -c / b
Label1.Caption = "方程只有一个根" & y
Else
Label1.Caption = "方程无意义" 颂镇猛'方程不成立的处理
End If
End Sub
展开全部
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
来自:求助得到的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-03-31
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询