Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:25
Show Gist options
  • Save pinglunliao/b1f6125b57e4d62f1db0 to your computer and use it in GitHub Desktop.
Save pinglunliao/b1f6125b57e4d62f1db0 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a, b, c;
while( cin >> a >> b >> c )
{
int check = b * b - 4 * a * c;
bool noRoot = check < 0;
if( noRoot == true )
{
cout << "No real root" << endl;
}
else
{
if( check == 0 )
{
int x = -b / (2 * a);
cout << "Two same roots x=" << x << endl;
}
else
{
int x1 = (-b + sqrtl(check)) / (2 * a);
int x2 = (-b - sqrtl(check)) / (2 * a);
cout << "Two different roots x1=" << x1 << " , x2=" << x2 << endl;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment