怪盗KID


私信TA

用户名:dotcpp0774863

访问量:582

签 名:

一万年太久,只争朝夕。

等  级
排  名 1912
经  验 2545
参赛次数 0
文章发表 20
年  龄 19
在职情况 学生
学  校 哔哩哔哩
专  业

  自我简介:


解题思路:利用求根公式

注意事项:导入数学库<math.h>

参考代码:

#include <stdio.h>
#include <math.h>
int main()
{
	float a, b, c;
	scanf("%f %f %f", &a, &b, &c);
	float x1, x2;
	float mysqrt;        
	
	if ((b * b - 4 * a * c) > 0) {
		mysqrt = sqrt(b * b - 4 * a * c);        //b^2 - 4ac开根号的值
	}
	x1 = ((-b) + mysqrt) / 2 * a;
	x2 = ((-b) - mysqrt) / 2 * a;

	if (x1 > x2) {
		printf("%.2f %.2f", x1, x2);
	}
	else {
		printf("%.2f %.2f", x2, x1);
	}

	return 0;
}


 

0.0分

1 人评分

  评论区

  • «
  • »