/*求方程 的根,用三个函数分别求当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 人评分
【计算两点间的距离】 (C语言代码)浏览:879 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:879 |
C语言训练-阶乘和数* (C语言代码)-------- 呆板写法浏览:1345 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:463 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:691 |
wu-理财计划 (C++代码)浏览:827 |
C语言训练-数字母 (C语言代码)浏览:600 |
sizeof的大作用 (C语言代码)浏览:1024 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:486 |
上车人数 (C语言代码)浏览:710 |