fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. int main(){
  5. float a,b,c,d,r1,r2,realp,imagp;
  6. printf("enter the coefficient ");
  7. scanf("%f%f%f",&a,&b,&c);
  8. if(a*b*c==0)
  9. {
  10. printf("enter a non 0 value ");
  11. exit(0);
  12.  
  13. }
  14. d=b*b-4*a*c;
  15. if(d==0)
  16. {
  17. printf("roots are equal ");
  18. r1=-b/(2*a);
  19. r2=-b/(2*a);
  20. printf("root1=root2=%f",r1 );
  21.  
  22. }
  23. else if(d>0)
  24. {
  25. printf("roots are real and distinct ");
  26. r1=(-b+sqrt(d)/(2*a));
  27. r2=(-b-sqrt(d)/(2*a ));
  28. printf("root1=%f,root2=%f ",r1,r2);
  29.  
  30. }
  31. else{
  32. printf(" roots are imaginary ");
  33. realp=-b/(2*a);
  34. imagp=sqrt(fabs(d)/(2*a ));
  35. printf("root1=%f+i*% f\n",realp,imagp);
  36. printf("root2=%f-i*%f\n ",realp,imagp);
  37.  
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
enter the coefficient enter a non 0 value