求个C++程序 在线等啊~~~

来源:百度知道 编辑:UC知道 时间:2024/06/11 15:50:06
求ax2+bx+c=0的根.用3个函数分别求当b2-4ac大于0,等于0和小于0时的根并输入结果.从键盘中输入a,b,c的值. 谢过各位C++大虾了~~~~

#include<iostream.h>
#include<math.h>
int root1(int a,int b,int c)
{
double x[2];
x[0]=(-b+sqrt(b*b-4*a*c))/(2*a);
x[1]=(-b-sqrt(b*b-4*a*c))/(2*a);
cout<<"The root is:\n"<<"x1="<<x[0]<<" x2="<<x[1]<<endl;
return 0;
}
int root2(int a,int b,int c)
{
double x[2];
x[0]=x[1]=sqrt(c/a);
cout<<"The root is:\n"<<"x1="<<x[0]<<" x2="<<x[1]<<endl;
return 0;
}
int root3(int a,int b,int c)
{
double x[2];
x[0]=(-b+sqrt(-(b*b-4*a*c)))/(2*a);
x[1]=(-b-sqrt(-(b*b-4*a*c)))/(2*a);
cout<<"The root is:\n"<<"x1="<<x[0]<<"i"<<" x2="<<x[1]<<"i"<<endl;
return 0;
}
int main()
{
int a,b,c;
cout<<&quo