60!!!!!!!!!!
查看原帖
60!!!!!!!!!!
1478203
dky001楼主2024/12/4 18:11

求助大佬,卡了好久了 代码如下:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	double a,b,c,x1,x2,_2a,_4ac,_b2;
	cin>>a>>b>>c;
	_2a=a*2;
	_4ac=4*a*c;
	_b2=b*b;
	double res=_b2-_4ac;
	if(res<0){
		cout<<"No answer!";
		return 0;
	}
	else if(res==0){
		cout<<"x1=x2="<<(-b)/_2a;
		return 0;
	}
	else{
		x1=(-b+sqrt(res))/_2a;
		x2=(-b-sqrt(res))/_2a;
		if(x1<x2){
			cout<<fixed<<setprecision(5)<<"x1="<<x1<<";"<<"x2="<<x2;
		}
		else{
			cout<<fixed<<setprecision(5)<<"x2="<<x2<<";"<<"x1="<<x1;
		}
	}
	
}


2024/12/4 18:11
加载中...