fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. float a, b, c, delta, x1, x2;
  6. printf("Nhap a, b, c: ");
  7. scanf("%f%f%f", &a, &b, &c);
  8.  
  9. if (a == 0) {
  10. if (b == 0) {
  11. if (c == 0)
  12. printf("Phuong trinh co vo so nghiem\n");
  13. else
  14. printf("Phuong trinh vo nghiem\n");
  15. } else {
  16. printf("Phuong trinh bac nhat, x = %.2f\n", -c / b);
  17. }
  18. } else {
  19. delta = b*b - 4*a*c;
  20. if (delta < 0)
  21. printf("Phuong trinh vo nghiem\n");
  22. else if (delta == 0)
  23. printf("Phuong trinh co nghiem kep x = %.2f\n", -b / (2*a));
  24. else {
  25. x1 = (-b + sqrt(delta)) / (2*a);
  26. x2 = (-b - sqrt(delta)) / (2*a);
  27. printf("Phuong trinh co 2 nghiem:\n");
  28. printf("x1 = %.2f\n", x1);
  29. printf("x2 = %.2f\n", x2);
  30. }
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Nhap a, b, c: Phuong trinh co nghiem kep x = -40649687908220928.00