fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void) {
  5.  
  6. int a, b, c;
  7. double disc, root1, root2;
  8.  
  9. // Read in the coefficients for the quadratic.
  10. printf("Enter in a, b and c from your quadratic equation.\n");
  11. printf("Please enter values so the equation has real roots.\n");
  12. scanf("%d%d%d", &a, &b, &c);
  13.  
  14. // Calculate the discriminant.
  15. disc = pow(b,2) - 4*a*c;
  16.  
  17. root1 = (-b + sqrt(b*b-4*a*c))/(2*a);
  18. root2 = (-b - sqrt(disc))/(2*a);
  19. printf("The roots are %.2lf and %.2lf.\n", root1, root2);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Enter in a, b and c from your quadratic equation.
Please enter values so the equation has real roots.
The roots are 48099.87 and -0.00.