c语言函数求方程的根 c语言 求方程的根( 二 )


while(T--) {
printf("请输入二次函数c语言函数求方程的根的系数a,b,c:");
scanf("%f,%f,%f",a,b,c);
roots(a,b,c);
}
return 0;
}
int roots(float a,float b,float c) {
double x1,x2,x;
double eps = 1.0E-7;
if((fabs(a) = eps)(fabs(b) = eps)) {
printf("Input error!\n");
return -1;
}
else {
if(fabs(a) = eps) {
x=-c/b;
printf("x = %.6lf",x);
}
else {
if((b*b-4*a*c) = 0) {
x1 = (-(double)b + sqrt((double)b*(double)b - 4*(double)a*(double)c))/(2*(double)a);
x2 = (-(double)b - sqrt((double)b*(double)b - 4*(double)a*(double)c))/(2*(double)a);
printf("x1 = %.6lf\nx2 = %.6lf\n",x1,x2);
}
else {
x1 = ((-(double)b)/(2*(double)a) + (((double)b*(double)b - 4*(double)a*(double)c)/(2*(double)a)));
x2 = ((-(double)b)/(2*(double)a) - (((double)b*(double)b - 4*(double)a*(double)c)/(2*(double)a)));
printf("x1 = %.6lfi\nx2 = %.6lfi\n",x1,x2);
}
}
}
return 0;
}
关于c语言函数求方程的根和c语言 求方程的根的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读