P.S. 公式:(-b+sqrt(b*b-4*a*c))/(2*a) 以及 (-b-sqrt(b*b-4*a*c))/(2*a)
[C++](5ms, 704KB)
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() | |
{ | |
int a, b, c; | |
while( cin >> a >> b >> c ) | |
{ | |
if( b*b - 4*a*c < 0 ) | |
cout << "No real root\n"; | |
else if( b*b - 4*a*c == 0 ) | |
cout << "Two same roots x=" << -b/(2*a) << endl; | |
else | |
cout << "Two different roots x1=" << (-b + sqrt(b*b-4*a*c)) / (2*a) << " , x2=" << (-b - sqrt(b*b-4*a*c)) / (2*a) << endl; | |
} | |
return 0; | |
} |
0 意見:
張貼留言