2019-06-06
08:47:59
adhere to! ! !
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 scanf("%d", &n); 7 while (n--) 8 { 9 int a,b,c; 10 scanf("%d %d %d", &a, &b, &c); 11 int m = b * b - 4 * a * c; 12 if(m < 0) 13 cout << "NO"; 14 else if(m == 0) 15 { 16 double x = (double)b * (-1) / (2 * a); 17 printf("%.2lf", x); 18 } 19 else 20 { 21 double x = ((double)b * (-1) - sqrt(m)) / (2 * a); 22 double y = ((double)b * (-1) + sqrt(m)) / (2 * a); 23 printf("%.2lf %.2lf", x, y); 24 } 25 cout << endl; 26 } 27 return 0; 28 }
Other approaches
Veda theorem: x1 + x2 = -b / a, x1 * x2 = c / a to solve x1-x2 = sqrt ((x1 + x2) * (x1 + x2) -4 * x1 * x2), in order to then be out of x1, x2 it! Also remember two decimal places yo!