42_一元二次方程

强颜欢笑 提交于 2020-01-10 04:12:50

解一元二次方程ax2+bx+c=0的解。题目保证有两个不同的解。

 

Input:

a,b,c的值。

Output:

两个根X1和X2,其中X1>=X2。。 结果保留两位小数。

Sample Input:

1 5 -2

Sample Output:

0.37 -5.37

****************************************************************************

#include<stdio.h>
#include<math.h>

int main()
{
    double a,b,c;
    scanf("%lf %lf %lf",&a,&b,&c);
    double x1 =( (-b) + sqrt(b * b - 4 * a * c) ) / ( 2 * a );
    double x2 =( (-b) - sqrt(b * b - 4 * a * c) ) / ( 2 * a );
    printf("%.2lf %.2lf",x1,x2);
    return 0;
}

***************************************************************************

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!