B2053,20分 谁来救救我
查看原帖
B2053,20分 谁来救救我
1256802
li_yuzhe楼主2024/4/21 19:58

请看代码

#include<bits/stdc++.h>
using namespace std;
int main(){
	double a,b,c,x1,x2;
	cin>>a>>b>>c;
	x1=(-b+sqrt(b*b-4*a*c))/2*a;
	x2=(-b-sqrt(b*b-4*a*c))/2*a;
	if(x1==x2) {
		cout<<"x1=x2=";
		printf("%.5f",x1);
	}
	else if(x1>x2){
		swap(x1,x2);
		cout<<"x1=";
		printf("%.5f",x1);
		cout<<";x2=";
		printf("%.5f",x2);
	}
	else if(x1<x2){
		cout<<"x1=";
		printf("%.5f",x1);
		cout<<";x2=";
		printf("%.5f",x2);
	}
	else cout<<"No answer!";
    return 0;
}
2024/4/21 19:58
加载中...