其他分享
首页 > 其他分享> > HUST 1541 Student’s question

HUST 1541 Student’s question

作者:互联网

2019-06-06

08:47:59

坚持!!!

 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 }

其他做法

韦达定理得:x1+x2=-b/a,x1*x2=c/a去求解x1-x2=sqrt((x1+x2)*(x1+x2)-4*x1*x2),然后就可以求出x1,x2啦!还要记得保留两位小数哟!

 

标签:06,cout,int,question,scanf,HUST,Student,x2,x1
来源: https://www.cnblogs.com/Artimis-fightting/p/10983058.html