对于一元二次方程 ax^2 + bx + c = 0,其求根公式为 x=((-b±√(b^2-4ac)))/((2a))。
- 判别式:b^2 - 4ac。判别式的值决定了方程的根的情况:
- 若判别式大于0,方程有两个不相等的实数根。
- 若判别式等于0,方程有两个相等的实数根。
- 若判别式小于0,方程无实数根。
通过求根公式,我们可以准确地找到一元二次方程的根。
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
double y,z;
scanf("%d %d %d",&a,&b,&c);
int x=(b*b-4*a*c);
if(x>0)
{
y=(-b+sqrt(x))/(2*a);
z=(-b-sqrt(x))/(2*a);
printf("there are two unequal roots %.2f,%.2f",y,z);
}else if(x==0)
{
y=(-b+sqrt(x))/(2*a);
printf("there are two equal roots %.2f",y);
}else if(x<0)
{
printf("the equation has no root");
}
return 0;
}