求方程ax ²+bx +c=0的根。
当a=0时,一元一次方程,当a≠0时一元二次方程,当b²-4ac ≥0时有实根,当b²-4ac <0时有虚根
#include<stdio.h>
#include<math.h>
int main(void)
{
int a,b,c;
float x1,x2;
scanf("%d %d %d",&a,&b,&c);
if(a==0)
{
if(b==0)
printf("input error\n");
else
x1=c/b;
printf("x=%f\n",x1);
}
else
{
if(bb-4ac>=0)
{
x1=-b+sqrt(bb-4ac);
x2=-b-sqrt(bb-4ac);
printf("x1=%f x2=%f\n",x1,x2);
}
else
{
x1=sqrt(-(bb-4ac));
x2=-sqrt(-(bb-4a*c));
b=-b;
printf("x1=%d+%fi x2=%d%fi\n",b,x1,b,x2);
}
}
return 0;
}