解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main()
{
double a, b, c, x1, x2;
cin >> a >> b >> c;
if ((b*b - 4 * a*c) > 0)
{
x1 = (-b + sqrt(b*b - 4.0 * a*c)) / (2 * a);
x2 = (-b - sqrt(b*b - 4.0 * a*c)) / (2 * a);
cout << setprecision(2) << fixed << x1 << " " << setprecision(2) << fixed << x2 << endl;
}
if ((b*b - 4 * a*c) == 0)
{
x1 = (-b) / 2;
x2 = x1;
cout << setprecision(2) << fixed << x1 << " " << setprecision(2) << fixed << x2 << endl;
}
if ((b*b - 4 * a*c) < 0)
{
x1 = sqrt(4.0 * a*c - b*b) / (2 * a);
x2 = sqrt(4.0 * a*c - b*b) / (2 * a);
cout << setprecision(2) << fixed << (-b) / 2 << "+" << setprecision(2) << fixed << x1 << "i " << setprecision(2) << fixed << (-b) / 2 << "-" << setprecision(2) << fixed << x2 << "i" << endl;
}
return 0;
}
0.0分
0 人评分
蛇行矩阵 (C++代码)(预生成结果以节省每次生成的时间)浏览:822 |
简单的a+b (C语言代码)浏览:538 |
C语言训练-求具有abcd=(ab+cd)2性质的四位数 (C语言代码)浏览:1372 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:2468 |
C语言程序设计教程(第三版)课后习题9.1 (Java代码)浏览:471 |
多输入输出练习1 (C语言代码)浏览:1189 |
printf基础练习2 (有点不明白)浏览:845 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:611 |
【计算直线的交点数】 (C语言代码)浏览:1453 |
简单的a+b (C语言代码)浏览:488 |