30分求助
查看原帖
30分求助
1461732
l_Zilch_l楼主2024/10/9 23:20
#include <bits/stdc++.h>
using namespace std;
int main()
{
    double a,b,c,d;
    cin>>a>>b>>c;
    d=b*b-4*a*c;
    if(d<0)
    {
    cout<<"No answer!";
    return 0;
    }
    else if(d==0)
    cout<<fixed<<setprecision(5)<<"x1=x2="<<-b/(2*a);
    else if(d>0)
    {
        double x1=-b+sqrt(d)/(2*a);
        double x2=-b-sqrt(d)/(2*a);
        if(x1>x2)
        {
            swap(x1,x2);
            cout<<fixed<<setprecision(5)<<"x1="<<x1<<";x2="<<x2;
        }
        else
        cout<<fixed<<setprecision(5)<<"x1="<<x1<<";x2="<<x2;
    }
    return 0;
}
2024/10/9 23:20
加载中...