fork download
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6. float a,b,c,d,root1,root2;
  7. cout<<"Enter 3 coefficients";
  8. cin>>a>>b>>c;
  9. d=b*b-4*a*c;
  10. if(d>0)
  11. {
  12. root1=(-b+sqrt(d))/(2*a);
  13. root2=(-b+sqrt(d))/(2*a);
  14. cout<<"roots are real and unequal";
  15. cout<<root1<<root2;
  16. }
  17. else if(d==0)
  18. {
  19. root1=-b/(2*a);
  20. cout<<"roots are real and unequal";
  21. cout<<root1;
  22. }
  23. else
  24. {
  25. cout<<"roots are complex and imaginary";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter 3 coefficientsroots are real and unequal1.96502e+191.96502e+19