c语言程序设计题目:计算一元二次方程的根

问题描述:

c语言程序设计题目:计算一元二次方程的根
【程序填空】
#include
//
else if(【?】)
{x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("has distinct real roots:%8.4f and %.4f\n",x1,x2);
}
else
{realpart=-b/(2*a);
imagpart=sqrt(-disc)/(2*a);
printf("has complex roots:\n");
printf("%8.4f=%.4fi\n",realpart,imagpart);
printf("%8.4f-%.4fi\n",realpart,imagpart);
}
}

#include
//
else if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("has distinct real roots:%8.4f and %.4f\n",x1,x2);
}
else
{
realpart=-b/(2*a);
imagpart=sqrt(-disc)/(2*a);
printf("has complex roots:\n");
printf("%8.4f+%.4fi\n",realpart,imagpart);
printf("%8.4f-%.4fi\n",realpart,imagpart);
}
}
}
2 -3 -5
the equationhas distinct real roots:2.5000 and -1.0000
Press any key to continue