解题思路:
注意事项:
参考代码:
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
void f1(double a, double b, double c)
{
int x1 = 0, x2 = 0;
x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
cout << "x1=" << setprecision(3) << x1 <<" "<< "x2=" << setprecision(3) << x2 << endl;
}
void f2(double a, double b, double c)
{
int x1 = 0, x2 = 0;
cout << "x1=" << setprecision(3) << -b/(2*a)<<"+"<<setprecision(3)<<sqrt(-(b * b - 4 * a * c))/(2*a) << "i "<< "x2=" << setprecision(3) << -b / (2 * a) << "-" <<setprecision(3)<< sqrt(-(b * b - 4 * a * c)) / (2 * a) << "i " << endl;
}
int main()
{
double a, b, c;
cin >> a >> b >> c;
double t = b * b - 4 * a * c;
if (t >= 0)
f1(a, b, c);
else
f2(a, b, c);
return 0;
}
0.0分
0 人评分
DNA (C++代码)浏览:650 |
破解简单密码 (C语言代码)浏览:1768 |
C二级辅导-计负均正 (C语言代码)浏览:598 |
不知道哪里错了浏览:1145 |
C语言程序设计教程(第三版)课后习题7.4 (Java代码)浏览:842 |
输出正反三角形 (C语言代码)格式错误!!!浏览:1141 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:790 |
WU-输出正反三角形 (C++代码)浏览:1021 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:506 |
C语言考试练习题_一元二次方程 (C语言代码)浏览:576 |