半年了,我依然过不去这道题
查看原帖
半年了,我依然过不去这道题
970708
fengyaun楼主2023/12/24 10:53

蒟蒻求调

#include<bits/stdc++.h>
using namespace std;
int main()
{
	double a, b, c, x1, x2;
	cin >> a >> b >> c;
	if (b * b - 4 * a * c < 0)
	{
		cout << "No answer!";
		return 0;
	}
	x1 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
	x2 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
	if (x1 == x2)
	{
		printf("x1=x2=%lf", x1);
	}
	else 
	{
		if (x1 < x2)
		{
			printf("x1=%.5lf;x2=%.5lf", x1, x2);
		}
		else
		{
			printf("x1=%.5lf;x2=%.5lf", x2, x1);
		}
	}
	return 0;
}
2023/12/24 10:53
加载中...