vb解二次函数代码问题!代码如下Private Sub Command1_Click()Dim a As Single,b As Single,c As SingleDim n As Single,m As Singlea = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)If b ^ 2 - 4 * a * c Label3.Caption = "无解"Elsen = -b + (b ^ 2 - 4 * a * c) ^ (1 / 2) / 2 * am = -b - (b ^ 2 - 4 * a * c) ^ (1 / 2) / 2 * aLabel3.Caption = "" + CStr(n) + " " + CStr(m) + ""End IfEnd Sub请问 哪错了?
问题描述:
vb解二次函数代码问题!
代码如下
Private Sub Command1_Click()
Dim a As Single,b As Single,c As Single
Dim n As Single,m As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If b ^ 2 - 4 * a * c Label3.Caption = "无解"
Else
n = -b + (b ^ 2 - 4 * a * c) ^ (1 / 2) / 2 * a
m = -b - (b ^ 2 - 4 * a * c) ^ (1 / 2) / 2 * a
Label3.Caption = "" + CStr(n) + " " + CStr(m) + ""
End If
End Sub
请问 哪错了?
答
一、你没有考虑a=0 的情况
二、n= 和m= 这两句,你要把 2*a 用() 括起来做分母 或者你把 * 号,换成除号 / 就不用括起来了!
还有楼上说的,分子也要括起来!哈哈