#include<iostream>
#include <cmath>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if (b*b-4*a*c<0)
{
cout<<"此方程无解。";
}
else if (b*b-4*a*c==0)
{
double x;
x=-b/(2*a);
cout<<"此方程解为:"<<x;
}
else
{
double x1,x2;
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
cout<<"此方程的解为:"<<x1<<"和"<<x2;
}
return 0;
}
c++用if语句编程求一元二次方程ax2 + bx + c = 0的解
最新推荐文章于 2023-12-31 14:07:44 发布