4 solutions

  • -2
    @ 2025-2-10 11:52:51
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        double a,b,c,x1,x2;
        cin>>a>>b>>c;
        if ((b*b-4*a*c)<0)
        {
            cout<<"No,answer!";
        }
        else{
            x1 = (-b+sqrt(pow(b,2)-4*a*c))/(2*a);
            x2 = (-b-sqrt(pow(b,2)-4*a*c))/(2*a);
            if ((b*b-4*a*c)==0)
            {
                cout<<"x1=x2="<<fixed<<setprecision(5)<<x1;
            }
            else if((b*b-4*a*c)>0){
                if(x1 < x2)
            {
                cout<<"x1="<<fixed<<setprecision(5)<<(-b+sqrt(pow(b,2)-4*a*c))/(2*a)<<';'<<"x2="<<(-b-sqrt(pow(b,2)-4*a*c))/(2*a);
            }else{
                cout<<"x1="<<fixed<<setprecision(5)<<(-b-sqrt(pow(b,2)-4*a*c))/(2*a)<<';'<<"x2="<<(-b+sqrt(pow(b,2)-4*a*c))/(2*a);
            
            }
            }
    
        }
        return 0;
    }
    

    Information

    ID
    865
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    (None)
    # Submissions
    125
    Accepted
    31
    Uploaded By