我是新手,我怕谁!!(非礼勿扰)(aX^2+bX+c=0)

Mars.CN 碳十四空间科技河北有限公司 CEO/总裁  2003-05-07 03:00:20
请问各路高手,有这样一道提,该如何做?
aX^2+bX+c=0
当a>0 b^2+4ac>0
b^2+4ac=0
b^2+4ac<0
当a=0 b^2+4ac>0
b^2+4ac=0
b^2+4ac<0
当a<0 b^2+4ac>0
b^2+4ac=0
b^2+4ac<0
时求出X的值
我要原程序,最好加上讲解,谢谢!
E-mail:suolong@sjzsoft.com


...全文
5 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
danielinbiti 2003-05-07
对不起,出了点错
这三句改称下面
a = CSng(InputBox(输入a的值))
b = CSng(InputBox(输入b的值))
c = CSng(InputBox(输入c的值))
回复
danielinbiti 2003-05-07
Sub calu()
Dim a As Single
Dim b As Single
Dim c As Single
Dim x1 As Single
Dim x2 As Single
Dim t As Single
Dim y As Single
a = Int(InputBox(输入a的值))
b = Int(InputBox(输入b的值))
c = Int(InputBox(输入c的值))
t = b ^ 2 + 4 * a * c
y = b ^ 2 - 4 * a * c
If a = 0 Then
If t = 0 And c = 0 Then x1 = 0: x2 = x1: Print x1
If t = 0 And c <> 0 Then Print "无解"
If t <> 0 Then
If b <> 0 Then x1 = -c / b: x2 = x1: Print x1
End If
End If
If a > 0 Or a < 0 Then
If y = 0 Then x1 = (-1 * b) / (2 * a): x2 = x1: Print x1
If y > 0 Then x1 = (-1 * b + Sqr(y)) / (2 * a): x2 = (-1 * b - Sqr(y)) / (2 * a): Print x1, x2
If y < 0 Then
Print "x1="; -1 * b / (2 * a) & "+" & Sqr(-y) / (2 * a) & "i",
Print "x2="; -1 * b / (2 * a) & "-" & Sqr(-y) / (2 * a) & "i"
End If
End If
End Sub
Private Sub Command1_Click()
calu
End Sub
看不懂你那个a<>0时,判断b^2+4ac干吗用
回复
tiande 2003-05-07
dim ls,x1,x2 as float
if a>0 or a<0 then
ls=sqr(b*b-4ac)
if ls>=0 then
x1=(-b+ls)/(2*a)
x2=(-b+ls)/(2*a)
else
msgbox "error"
end if
else
x1=x2=-c/b
end if

незнаю
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7491

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-07 03:00
社区公告
暂无公告