解题思路:读取输入,然后解方程,最后比较两个根,我就忘记比较了
注意事项:本次发i心安了一个问题,就是这个? :运算符,后边的语句要带括号x1 > x2 ? :temp = x1, x1 = x2, x2 = temp;假如我这样写,答案就是错误的,希望引以为戒,我港式不知道哪里出了问题找了半天。
参考代码:
#include<iostream> #include <iomanip> #include <math.h> using namespace std; int main() { double a, b, c; double x1, x2, dert; double temp; cin >> a >> b >> c; if(a != 0){ dert = pow(b, 2) - 4 * a * c; x1 = ((-1) * b + sqrt(dert)) / a / 2; x2 = ((-1) * b - sqrt(dert)) / a / 2; x1 > x2 ? :(temp = x1, x1 = x2, x2 = temp); } else{ x1 = (-1) * c / b; x2 = x1; } cout << fixed << setprecision(2) << x1 << ' ' << x2 << endl; return 0; }
0.0分
1 人评分
输出九九乘法表 (C语言代码)浏览:572 |
C语言程序设计教程(第三版)课后习题12.5 (C语言代码)浏览:860 |
钟神赛车 (C++代码)浏览:901 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)for循环浏览:1167 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:988 |
求圆的面积 (C语言代码)浏览:1356 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:567 |
【金明的预算方案】 (C++代码)浏览:984 |
【矩阵】 (C++代码)浏览:983 |
1011题解浏览:810 |