#include
#include
#include
using namespace std;
int main()
{
double a=1, b=1, c=1, d=1;
cout << "Enter a,b,c:";
d = b * b - 4 * a * c;
cin >> a >> b >> c;
if (0==a) {if(0==b)cout<<"方程不成立\n";
else cout<< "x =" << fixed << setprecision(2) << -c / b << endl;}</span><br /><span style="display:inline-block;text-indent:2em;"> else if (d >= 0) {
cout << "x1 =" << fixed << setprecision(2) << (-b + sqrt(d)) / (2 * a) << endl;</span><br /><span style="display:inline-block;text-indent:2em;"> cout << "x2 =" << fixed << setprecision(2) << (-b - sqrt(d)) / (2 * a) << endl;</span><br /><span style="display:inline-block;text-indent:2em;"> }
else {
cout << "x1 =" << fixed << setprecision(2) << -b / (2 * a) << " + " << sqrt(-d) / (2 * a) << "i" << endl;
cout << "x2 =" << fixed << setprecision(2) << -b / (2 * a) << " - " << sqrt(-d) / (2 * a) << "i" << endl;
}
return 0;
}
为什么是错的求解答刚刚学
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- qzjhjxj 2022-10-15 22:47关注
修改如下,供参考:
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double a=1, b=1, c=1, d=1; cout << "Enter a,b,c:"; cin >> a >> b >> c; //修改 d = b * b - 4 * a * c; //修改 if (0 == a) { if(0 == b) cout<<"方程不成立\n"; else cout<< "x =" << fixed << setprecision(2) << -c / b << endl; } else if (d >= 0) { cout << "x1 =" << fixed << setprecision(2) << (-b + sqrt(d)) / (2 * a) << endl; cout << "x2 =" << fixed << setprecision(2) << (-b - sqrt(d)) / (2 * a) << endl; } else { cout << "x1 =" << fixed << setprecision(2) << -b / (2 * a) << " + " << sqrt(-d) / (2 * a) << "i" << endl; cout << "x2 =" << fixed << setprecision(2) << -b / (2 * a) << " - " << sqrt(-d) / (2 * a) << "i" << endl; } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 MPI读取tif文件无法正常给各进程分配路径
- ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
- ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
- ¥15 setInterval 页面闪烁,怎么解决
- ¥15 如何让企业微信机器人实现消息汇总整合
- ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
- ¥15 如何用Python爬取各高校教师公开的教育和工作经历
- ¥15 TLE9879QXA40 电机驱动
- ¥20 对于工程问题的非线性数学模型进行线性化
- ¥15 Mirare PLUS 进行密钥认证?(详解)