fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. void main()
  4. {
  5. float a,b,c,disc,x1,x2,realpart,imagpart;
  6. scanf("%f,%f,%f",&a,&b,&c);
  7. printf("The equation");
  8. if(fabs(a)<=1e-6)
  9. printf("is not a quadratic\n");
  10. else
  11. {
  12. disc=b*b-4*a*c;
  13. if(fabs(disc)<=1e-6)
  14. printf("has two equal roots:%8.4f\n",-b/(2*a));
  15. else
  16. if(disc>1e-6)
  17. {
  18. x1=(-b+sqrt(disc))/(2*a);
  19. x2+(-b-sqrt(disc))/(2*a);
  20. printf("has distinct real roots:%8.4f and %8.4f\n",x1,x2);
  21. }
  22. else
  23. {
  24. realpart=-b/(2*a);
  25. imagpart=sqrt(-disc)/(2*a);
  26. printf("has complex roots:\n");
  27. printf("%8.4f+%8.4fi\n",realpart,imagpart);
  28. printf("%8.4f-%8.4fi\n",realpart,imagpart);
  29. }
  30. }
  31. }
Success #stdin #stdout 0s 5320KB
stdin
2,6,1
stdout
The equationhas distinct real roots: -0.1771 and   0.0000