编一个程序,对于给定a,b,c的值,求出一元二次方程a*x*x+b*x+c=0的二个实数根,如果没有实数根,则说明即可

来源:互联网 发布:淘宝评价语20字 编辑:程序博客网 时间:2024/06/05 00:54
declare @a int,@b int,@c int,@x float,@x1 float,@d int
select @a=2,@b=4,@c=2
set @d=(@b*@b-4*@a*@c)
if @d=0
  set  @x=-@b/2*@a
  set  @x1=-@b/2*@a
  select @x,@x1 as '3*x*x+5*x+4=0的解' 


if @d<0
print '无解' 
else
set @x=(-1*@b+sqrt(@d))/(2*@a)
set @x1=(-1*@b-sqrt(@d))/(2*@a)
--select @x,@x1 as '3*x*x+5*x+4=0的解'
print @x
print @x1
 
原创粉丝点击