fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5. int main()
  6. {
  7. float a,b,c,d,x1,x2;
  8. cin>>a>>b>>c;
  9. d= b*b - 4*a*c;
  10. if (d>=0){
  11. x1=(-b+sqrt(d))/(2*a);
  12. x2=(-b-sqrt(d))/(2*a);
  13. if(x1==int(x1)) cout<<x1<<' ';
  14. else
  15. cout<<fixed<<setprecision(2)<<x1<<' ';
  16. if(x2==int(x2)) cout<<x2<<' ';
  17. else
  18. cout<<fixed<<setprecision(2)<<x2<<' ';
  19. }
  20. else cout<<"方程无实数解"<<endl;
  21. return 0;
  22. }
  23.  
  24.  
Success #stdin #stdout 0s 16064KB
stdin
1 3 4
stdout
方程无实数解