十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
# include
# include /*此头文件为调用 sqrt() 求平方根而用*/
int main(void)
{
int a;
int b;
int c;
double x1;
double x2;
double delta; //定义 delta = b*b = 4*a*c
/*请用户输入三个整数 a b c, 并分别以空格键为间隔*/
printf("请分别输入一元二次方程 a b c 的三个数值,请以空格为间隔:\n");
scanf("%d %d %d", &a, &b, &c);
delta = b*b - 4*a*c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("该一元二次方程有两个解: x1 = %lf, x2 = %lf\n", x1, x2);
}
else if (delta == 0)
{
x1 = (-b) / (2*a);
x2 = x1;
printf("该一元二次方程有一个解: x1 = x2 = %lf\n", x1);
}
else
{
printf("无解\n");
}
return 0;
}