Last active
November 5, 2019 08:25
-
-
Save pinglunliao/b1f6125b57e4d62f1db0 to your computer and use it in GitHub Desktop.
a006: 一元二次方程式 FYI: https://yunlinsong.blogspot.com/2016/01/blog-post_29.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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