求助C语言答案.急求.

来源:百度知道 编辑:UC知道 时间:2024/06/10 12:19:02
请补充main函数,该函数的功能是求方程ax2+bx+c=0的两个实数根。方程的 系数a、b、c从键盘输入,如果判别式(disc=b*b-4*a*c)小于0,则要求从新输 入a、b、c的值。一元二次方程的求根公式为:
例如:当a=1,b=2,c=1时,方程的两个根分别是:x1=-1.00,x2=-1.00.

#include <math.h>
#include <stdio.h>
main()
{
double a, b, c, disc, x1, x2;
do
{
printf("Input a, b, c: ");
scanf("%lf,%lf,%lf", &a, &b, &c);
disc = b*b - 4*a*c;
if (disc < 0)
printf("disc=%lf \n Input again!\n", disc);
} while (___1___);
printf("*******the result*******\n");
x1 = (-b+___2___(disc))/(2*a);
x2 = (-b-___3___(disc))/(2*a);
printf("\nx1=%6.2lf\nx2=%6.2lf\n", x1, x2);
}

#include <math.h>
#include <stdio.h>
main()
{
double a, b, c, disc, x1, x2;
do
{
printf("Input a, b, c: ");
scanf("%lf,%lf,%lf", &a, &b, &c);
disc = b*b - 4*a*c;
if (disc < 0)
printf("disc=%lf \n Input again!\n", disc);
} while (disc < 0); //输入错误,再重新输入
printf("*******the result*******\n");
x1 = (-b+sqrt(disc))/(2*a); //开方
x2 = (-b-sqrt(disc))/(2*a); //开方
printf("\nx1=%6.2lf\nx2=%6.2lf\n", x1, x2);
}