C++用函数求一元二次方程的根,

问题描述:

C++用函数求一元二次方程的根,
a)定义函数完成求解一元二次方程.函数的参数为一元二次方程的三个系数,无返回值,输出求解结果即可.b)在主函数中读取参数,并调用求根函数.
c)输入至少三组数据,观察 等于,小于,和大于零的输出.
d)若根为虚数,则在虚部后加字符以示区别.
注:

#include
#include
#include
main()
{
float a ,b,c,delta,x1,x2,y1,y2;
do
{
printf("please input the factors of a quadratic equation:a,b,c\n");
scanf("%f%f%f",&a,&b,&c);
printf("a=%f,b=%f,c=%f\n",a,b,c);
delta=b*b-4*a*c;
if(a==0&&b==0)
{
printf("the quadratic equation has no any root\n");
}
else if(a!=0)
{ if(delta>=0)
{
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("the roots of the quadratic equation:x1=%.2f,x2=%.2f\n",x1,x2);
}
else
{
x1=x2=-b/(2*a);
y1=y2=sqrt(abs(delta))/(2*a);
printf("the roots of the quadratic equation:x1=%.2f+i%.2f,x2=%.2f-i%.2f\n",x1,y1,x2,y2);
}
}
else if(a==0)
{
x1=x2=-c/b;
printf("x1=x2=%.2f\n",x1);
}
printf("Press \"q\" key to exit programe! \n");
}while(getch()!='q');
getch();
}是C++设计不是C