Liamcoder


私信TA

用户名:18817572995

访问量:9587

签 名:

Where there is a will, there is a way.

等  级
排  名 1881
经  验 2488
参赛次数 2
文章发表 11
年  龄 0
在职情况 学生
学  校 上海师范大学
专  业 计算机科学与技术

  自我简介:

屌丝程序狗

/*求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。*/ 

#include<iostream>

#include<iomanip>

#include<cmath>


using namespace std;

void getEquation(double a, double b, double c);

double delt;


int main()

{

double a, b, c;

cin >> a >> b >> c;

getEquation(a, b, c); 

return 0;

}


void getEquation(double a, double b, double c)

{

double x1, x2;

delt = b * b - 4 * a * c;

if(delt<0)

{

delt=-delt;

cout<<"x1="<<setprecision(3)<<setiosflags(ios::fixed)<<-b/(2*a)<<'+'<<sqrt(delt)/(2*a)<<'i'<<' ';

cout<<"x2="<<setprecision(3)<<setiosflags(ios::fixed)<<-b/(2*a)<<'-'<<sqrt(delt)/(2*a)<<'i'<<endl;

}

else

{

cout<<"x1="<<setprecision(3)<<setiosflags(ios::fixed)<<-(b+sqrt(delt))/(2*a)<<' ';

cout<<"x2="<<setprecision(3)<<setiosflags(ios::fixed)<<-(b-sqrt(delt))/(2*a)<<endl;

}

}


 

0.0分

0 人评分

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

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

代码解释器

代码纠错

SQL生成与解释

  评论区