⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5_6.c

📁 c_tan:谭浩强编著c语言程序设计一书的c程序源文件
💻 C
字号:
/*求ax^ +bx + c = 0的方程的解.
a = 0 ,不是二次方程;
b^ -4ac = 0,有两个相等实根;
b^ -4ac > 0,有两个不等实根;
b^ -4ac < 0,有两个共厄复根;
*/
# include <math.h>
# include <stdio.h>
main()
{	printf("请输入二次方程的a,b,c.它们在方程式中的含义这样的:ax^ + bx + c = 0 \n");
	printf("输入abc的时候,用逗号分隔!!!!\n");
	float a,b,c,d,disc,x1,x2,realpart,imagpart;
	if (scanf("%f,%f,%f",&a,&b,&c)<=0) {
		printf("非法输入");
		//return -1;
		exit();
	}
	printf("The equation ");

	disc = b*b-4*a*c;
	if (fabs(a)<=1e-6) printf("is not a quadratic");

	else if (fabs(disc) <= 1e-6) printf("has two equal roots:%8.4\n",-b/(2*a));
	else if (disc>1e-6) {
		x1 = (-b + sqrt(disc))/(2*a);
		x2 = (-b - sqrt(disc))/(2*a);
		printf("has two distinct real roots:%8.4f and %8.4f\n",x1,x2);
	}
	else {
		realpart = -b/(2*a);
		imagpart = sqrt(-disc)/(2*a);
		printf("has complex roots:\n");
		printf("%8.4f + %8.4fi\n",realpart,imagpart);
		printf("%8.4f - %8.4fi\n",realpart,imagpart);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -