fork(1) download
  1. #include <iostream>
  2. #include<math.h>
  3. using namespace std;
  4. int main()
  5. {
  6. float a,b,c,d,e,f,g,h,i,j;
  7. cin>>a;
  8. cin>>b;
  9. cin>>c;
  10. d=b*b-4*a*c;
  11. e=-b/(2*a);
  12. f=sqrt(d)/(2*a);
  13. g=sqrt(-d)/(2*a);
  14. h=e+f;
  15. i=e-f;
  16. if (d==0)
  17. {
  18. cout<<"root are equal ="<<e<<"";
  19. }
  20. if(d>0)
  21. {
  22. cout<<"roots are "<<h<<" and "<<i<<"";
  23. }
  24. if(d<0)
  25. {
  26. cout<<"roots are"<<e<<"+i"<<g<<" and "<<e<<"-i"<<g<<"";
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 4384KB
stdin
1 2 1
stdout
root are equal =-1