4 solutions

  • 2
    @ 2025-3-16 15:34:05
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	double a,b,c,x1/*根1*/,x2/*根2*/,n;
    	cin>>a>>b>>c;
    	n = b*b-4*a*c;
    	if (n>=0)//有解
    	{
    		x1 = (-b+sqrt(n))/(2*a);//根1
    		x2 = (-b-sqrt(n))/(2*a);//根2
    		if (n==0) cout<<fixed<<setprecision(5)<<"x1=x2="<<x1;//根相等
    		else if (x1<x2) cout<<fixed<<setprecision(5)<<"x1="<<x1<<";x2="<<x2;
    		else cout<<fixed<<setprecision(5)<<"x1="<<x2<<";x2="<<x1;
    	}
    	else cout<<"No answer!";//无解
    	return 0;
    }
    

    Information

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