AcWing 658. 一元二次方程公式
原题链接
简单
作者:
Pinkie
,
2024-04-17 10:46:06
,
所有人可见
,
阅读 4
C++ 代码
#include<bits/stdc++.h>
using namespace std;
double a,b,c;
int main()
{
cin>>a>>b>>c;
double der=b*b-4*a*c;
if(a==0||der<0)cout<<"Impossivel calcular";
else if(der==0)
{
cout<<"R1 = "<<fixed<<setprecision(5)<<(sqrt(der)-b)/(2*a)<<endl;
cout<<"R2 = "<<fixed<<setprecision(5)<<(sqrt(der)-b)/(2*a);
}
else
{
cout<<"R1 = "<<fixed<<setprecision(5)<<(sqrt(der)-b)/(2*a)<<endl;
cout<<"R2 = "<<fixed<<setprecision(5)<<(-sqrt(der)-b)/(2*a);
}
return 0;
}