发布网友
共1个回答
热心网友
#include<stdio.h>
#include<math.h>
#include<stdlib.h>int main()
{
double a=0.0,b=0.0,c=0.0,answer1,answer2;
printf("输入a:");
scanf("%lf",&a);
printf("输入b:");
scanf("%lf",&b);
printf("输入c:");
scanf("%lf",&c); answer2 = answer1 = b*b-4*a*c; if(answer1<0)
{
printf("无法计算!");
exit(0);
}
if(answer1>0)
{
answer1 = (-b+sqrt(answer1))/(2*a);
answer2 = (-b-sqrt(answer2))/(2*a);
}
else if(answer1==0)
{
answer2 = answer1 = (-b+sqrt(answer1))/(2*a);
} printf("结果:");
printf("x1=%lf\n",answer1);
printf("x2=%lf\n",answer2);
return 0;
}