42_一元二次方程

解一元二次方程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;
}

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

发布了37 篇原创文章 · 获赞 4 · 访问量 1943

猜你喜欢

转载自blog.csdn.net/qq_41440031/article/details/103879998
今日推荐