lcg007


私信TA

用户名:qq1102765728

访问量:17717

签 名:

Null

等  级
排  名 482
经  验 4521
参赛次数 1
文章发表 34
年  龄 0
在职情况 在职
学  校 同济大学
专  业

  自我简介:


解题思路:

注意事项:

参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区