# define _CRT_SECURE_NO_WARNINGS 1
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main(void)
{
double a, b, c, x1, x2, p;
printf("请依次输入一元二次方程的三个参数a b c,中间以空格隔开\n");
scanf("%f %f %f", &a, &b, &c);
p = b*b - 4*a*c;
if(p > 0)
{
x1 = (-b + sqrt(p)) / (2*a);
x2 = (-b - sqrt(p)) / (2*a);
printf("此一元二次方程有两个解,两个解分别为,x1 = %f, x2 = %f\n",x1, x2);
}
else if(p = 0)
{
x1 = (-b / 2*a);
x2 = x1;
printf("此一元二次方程有唯一解,x1 = %f\n", x1);
}
if(p < 0)
{
printf("此一元二次方程无解\n");
}
system("pause");
return 0;
}
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main(void)
{
double a, b, c, x1, x2, p;
printf("请依次输入一元二次方程的三个参数a b c,中间以空格隔开\n");
scanf("%f %f %f", &a, &b, &c);
p = b*b - 4*a*c;
if(p > 0)
{
x1 = (-b + sqrt(p)) / (2*a);
x2 = (-b - sqrt(p)) / (2*a);
printf("此一元二次方程有两个解,两个解分别为,x1 = %f, x2 = %f\n",x1, x2);
}
else if(p = 0)
{
x1 = (-b / 2*a);
x2 = x1;
printf("此一元二次方程有唯一解,x1 = %f\n", x1);
}
if(p < 0)
{
printf("此一元二次方程无解\n");
}
system("pause");
return 0;
}