c++,90分,#2出的问题,大佬们求助!
查看原帖
c++,90分,#2出的问题,大佬们求助!
790952
EASTdd楼主2022/9/13 13:45
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
	double a,b,c,de,x1,x2,deg;//三个系数,德尔塔,两个根,塔尔塔开方后 
	cin>>a>>b>>c;
	de=b*b-4*a*c;
	if (de>0){
		deg=sqrt(de);
		x1=(-b+deg)/(2*a);
		x2=(-b-deg)/(2*a);
		if (x1>x2){swap(x1,x2);}
		cout<<"x1=";
		cout<<fixed<<setprecision(5)<<x1;
		cout<<";";
		cout<<"x2=";
		cout<<fixed<<setprecision(5)<<x2;
	} else if(de=0){
		deg=sqrt(de);
		x1=-b/(2*a);
		cout<<"x1=x2=";
		cout<<fixed<<setprecision(5)<<x1;
	}else{
		cout<<"No answer!";
	}
	
	return 0;
}

2022/9/13 13:45
加载中...