/*求方程 的根,用三个函数分别求当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语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:582 |
C语言训练-角谷猜想 (C++代码)(3N+1问题)浏览:1744 |
求圆的面积 (C语言代码)浏览:1265 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:517 |
WU-字符串比较 (C++代码)浏览:754 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:522 |
K-进制数 (C语言描述,蓝桥杯)浏览:924 |
核桃的数量 (C语言代码)浏览:668 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:537 |
时间转换 (C语言代码)浏览:624 |