求一元二次方程的解:

时间:2023-01-18 00:01:19


#define EXP 0.000000000001

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
 double a=0.0,b=0.0,c=0.0;
 scanf("%lf %lf %lf",&a,&b,&c);
 if((a>-EXP)&&(a<EXP))
 {
  printf("not\n");
 }
 else
 {
  double d=b*b-4*a*c;
  if((d>-EXP)&&(d<EXP))
  {
   printf("两个相等的实根:%lf\n",-b/(2*a));
  }
  else if(d>0.0)
  {
   printf("有两个不相等的实根:%lf %lf\n",-b+sqrt(d)/(2*a), -b-sqrt(d)/(2*a));

  }
  else
  {
   printf("有两个共轭复根:");
  }
 }
 system("pause");
 return 0;
}