![]() |
#2
rjsp2021-02-01 08:43
|

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
double a,b,c,d,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);
d=b*b-4*a*c;
if(d<0){
cout<<"No answer!";
}
else{
if(x1==x2){
printf("x1=x2=%.5f",x1);
}
else{
if(x1>x2){
printf("x2=%.5f;x1=%.5f",x2,x1);
}
if(x1<x2){
printf("x1=%.5f;x2=%.5f",x1,x2);
}
}
}
return 0;
}
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
double a,b,c,d,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);
d=b*b-4*a*c;
if(d<0){
cout<<"No answer!";
}
else{
if(x1==x2){
printf("x1=x2=%.5f",x1);
}
else{
if(x1>x2){
printf("x2=%.5f;x1=%.5f",x2,x1);
}
if(x1<x2){
printf("x1=%.5f;x2=%.5f",x1,x2);
}
}
}
return 0;
}
题目链接:http://ybt.
[此贴子已经被作者于2021-1-31 15:21编辑过]