fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. float a, b, c, delta, y1, y2;
  6.  
  7. printf("Enter a, b, c: ");
  8. scanf("%f %f %f", &a, &b, &c);
  9.  
  10. delta = b * b - 4 * a * c;
  11.  
  12. if (delta < 0) {
  13. printf("No real solution\n");
  14. } else {
  15. y1 = (-b + sqrt(delta)) / (2 * a);
  16. y2 = (-b - sqrt(delta)) / (2 * a);
  17.  
  18. if (y1 > 0) {
  19. printf("x1 = %.2f\n", sqrt(y1));
  20. printf("x2 = %.2f\n", -sqrt(y1));
  21. } else if (y1 == 0) {
  22. printf("x = 0\n");
  23. }
  24.  
  25. if (y2 > 0) {
  26. printf("x3 = %.2f\n", sqrt(y2));
  27. printf("x4 = %.2f\n", -sqrt(y2));
  28. } else if (y2 == 0) {
  29. printf("x = 0\n");
  30. }
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 5316KB
stdin
1 - 5 4
stdout
Enter a, b, c: x1 = 0.00
x2 = -0.00