a*x*x+b*x+c=0方程的解

2023-12-17 16:17:52

1.b*b+4a*c=0,有两个相等实根

2.b*b+4a*c>0,有两个不相等实根

3.b*b+4a*c<0,有两个共轭实根(p-qi)(p+qi)

#include<stdio.h>
#include<math.h>
int main()
{
	printf("请计算a*x*x+b*x+c=0的值\n");
	double a = 0.0, b = 0.0, c = 0.0;
	double shishu = 0.0, gonge = 0.0;
	printf("请输入a,b,c的值:");
	scanf("%lf %lf %lf",&a,&b,&c);
	double m = 0.0,x1=0.0,x2=0.0;
	m = sqrt(b * b - 4 * a * c);
	if (m > 0)
	{
		x1 = (-b + m) / (2*a);
		x2 = (-b - m) / (2*a);
		printf("x1=%8.4lf x2=%8.4lf\n", x1, x2);
	}
	else if (m ==0 )
	{
		x1 = x2 = (-b) / (2 * a);
		printf("x1=x2=%lf\n",x2);
	}
	else
	{
		shishu =( -b) / (2 * a);
		gonge = sqrt(-(b * b - 4 * a * c)) / (2 * a);
		printf("x1=%8.4lf+%8.4lfi\n",shishu,gonge);
		printf("x2=%8.4lf-%8.4lfi\n", shishu, gonge);
	}
	return 0;
}

输出相等结果:

输出不相等实根:

输出共轭复根:

文章来源:https://blog.csdn.net/2301_78189441/article/details/134956326
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。