20171207一元二次方程

来源:互联网 发布:ipad版淘宝不支持横屏 编辑:程序博客网 时间:2024/05/16 19:50

Description

#include <iostream>#include <cmath>#include <iomanip>using namespace std;int main(){double a, b, c, d,e, x1, x2,t;cin >> a >> b >> c;d = b*b - 4 * a*c;e=-b / (2 * a);if (d > 0){x1 = (-b - sqrt(d)) / (2 * a);x2 = (-b + sqrt(d)) / (2 * a);if(x1<x2){        t=x1;        x1=x2;        x2=t;    }cout<<setiosflags(ios::fixed)<<setprecision(2)<<x1<<" "/*setprecision(3)*/<<x2<<endl;}else if (d < 0)cout << "无解" << endl;elsecout << setiosflags(ios::fixed)<<setprecision(2)<<e;}

解一元二次方程ax2+bx+c=0的解。

Input

a,b,c的值。


Output

两个根x1x2,其中  x1>=x2结果保留两位小数

原创粉丝点击