求助!C++编程题 重金 求解!

来源:百度知道 编辑:UC知道 时间:2024/05/15 12:16:06
按照下列要求编写程序:求方程ax2 +bx+c=0的根,分别求当b2-4ac大于0、等于0和小于0时的根,并输出结果。a,b,c的值从键盘输入。
哪位大虾会C++编程的,速速回答,多谢多谢!

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
double a,b,c;
cout<<"input a,b,c:";
cin>>a>>b>>c;
if(a == 0.0)
{
if(b!=0)cout<<"一元一次方程 root = "<<-c/b<<endl;
else
{
if (c!=0)cout<<"impossible\n";
else cout<<"forever equal!";
}
return 1;
}
double t = b*b - 4*a*c;
if( t > -0.000000000001 && t < 0.000000000001)
{
cout<<"1 root:"<<-b/2/a<<endl;
}
else if (t > 0.000000000001)
{
cout<<"2 roots:"<<(-b+sqrt(t))/2/a<<"\t"<<(-b-sqrt(t))/2/a<<endl;
}
else
{
t = sqrt(-t)/2/a;
double r = -b/2/a;
cout<<"无实根! 虚根是:"<<-b<<"±"<<t<<&qu