fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5. int main()
  6. {
  7. float a;
  8. float b;
  9. float c;
  10. float d;
  11. float r1;
  12. float r2;
  13.  
  14. scanf("%f %f %f ", &a, &b, &c);
  15.  
  16. d = b*b - 4*a*c;
  17.  
  18. if(d > 0)
  19. {
  20. r1 = (-b + sqrt(d)) / (2*a);
  21. r2 = (-b - sqrt(d)) / (2*a);
  22.  
  23. printf("roots are real and distinct\n");
  24. printf("%.2f %.2f", r1, r2);
  25. }
  26. else if (d == 0)
  27. {
  28. r1 = -b / (2*a);
  29.  
  30. printf("roots are real and equal\n");
  31. printf("%.2f %.2f", r1, r1);
  32. }
  33. else
  34. {
  35. printf("roots are complex");
  36. }
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 5320KB
stdin
1 1 -2
stdout
roots are real and distinct
1.00 -2.00