fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #define ESP 1e-6
  5. int main(void) {
  6. float a,b,c,disc,p,q;
  7. printf("Please enter the cofficients a,b,c:");
  8. scanf("%f,%f,%f",&a,&b,&c);
  9. if(fabs(a)<=ESP);{
  10. printf("It is not a quadratic equation!\n");
  11. exit(0);
  12. }
  13. disc=b*b-4*a*c;
  14. p=-b/(2*a);
  15. q=sqrt(fabs(disc))/(2*a);
  16. if(fabs(disc)<=ESP){
  17. prinyf("x1=x2=%.2f,x2=%.2f\n",p);
  18. }
  19. else {
  20. if(disc>ESP){
  21. printf("x1=%.2f,x2=.2f\n",p+q,p-q);
  22. }
  23. else
  24. {
  25. printf("x1=%.2f+%.2fi",p,q);
  26. printf("x2=%.2f-%.2fi",p,q);
  27. }
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5320KB
stdin
1,2,1
stdout
Please enter the cofficients a,b,c:It is not a quadratic equation!