#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void getRoot(const double& a, const double& b, const double& delta);
void getRoot(const double& a, const double& b);
void getRoot(const double& a, const double& b, const double& delta, const char& i);
int main(void)
{
double a, b, c;
double delta;
cin >> a >> b >> c;
delta = b*b - 4*a*c;
if (delta > 0)
{
getRoot(a, b, delta);
}
else if (delta == 0)
{
getRoot(a, b);
}
else
{
getRoot(a, b, delta, 105);
}
return 0;
}
void getRoot(const double& a, const double& b, const double& delta)
{
double x1, x2;
double temp = sqrt(delta);
x1 = (-b + temp) / (2*a);
x2 = (-b - temp) / (2*a);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
cout << "x1=" << x1 << " " << "x2=" << x2 << endl;
}
void getRoot(const double& a, const double& b)
{
double x;
x = -b / (2*a);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
cout << "x=" << x << endl;
}
void getRoot(const double& a, const double& b, const double& delta, const char& i)
{
double temp = sqrt(-delta);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
cout << "x1=" << (-b / (2*a)) << "+" << (temp / (2*a)) << i << " ";
cout << "x2=" << (-b / (2*a)) << "-" << (temp / (2*a)) << i << endl;
}
0.0分
2 人评分