求助C语言答案.急求.
请补充main函数,该函数的功能是求方程ax2+bx+c=0的两个实数根。方程的系数a、b、c从键盘输入,如果判别式(disc=b*b-4*a*c)小于0,则要求从新输入...
请补充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);
} 展开
例如:当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);
} 展开
1个回答
展开全部
#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);
}
#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);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询