fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double solve(double a,double b,double c){
  5. if(a==0){
  6. return -c/b;
  7. }
  8. if(b*b-4*a*c<0){
  9. printf("Complex\n");
  10. return 0;
  11. }
  12. return (-b+sqrt(b*b-4*a*c))/2/a;
  13. }
  14.  
  15. int main(void){
  16. double a,b,c,x;
  17. a=1.0;
  18. b=3.0;
  19. c=2.0;
  20. x=solve(a,b,c);
  21. printf("x=%lf\n",x);
  22. return 0;
  23. }
Success #stdin #stdout 0.02s 1676KB
stdin
Standard input is empty
stdout
x=-1.000000