// 计算一元二次方程
#include <iostream>
#include <math.h> //函数调用
using namespace std;
int main()
{
float a ,b ,c;
double anto ;
cout << "请输入二次项系数 a :";
cin >> a ;
cout << "请输入一次项系数 b :";
cin >> b ;
cout << "请输入常数项 c :";
cin >> c ;
if(a==0&&b==0)
{
cout << "该方程不是一元二次方程"<< endl;
}
anto = (b*b)-(4*a*c) ;
if (anto >= 0){
if (anto > 0){
cout << "方程的实数根 X1= " << (-b+sqrt(anto))/(2*a) << endl;
cout << " 方程的实数根X2= " << (-b-sqrt(anto))/(2*a) << endl;
}
else cout << "方程的实数根 X1 = X2 = " << (-b)/(2*a) << endl;
}
else {
anto=abs(anto);
cout << "方程的虚根X=" << -b/(2*a) <<"±"<<sqrt(anto)/(2*a) <<"j"<< endl;
}
return 0;
}
计算一元二次方程组
最新推荐文章于 2023-12-25 11:03:32 发布