赞
踩
Description:
解一元二次方程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, x2;
- double d = sqrt(b * b - 4 * a * c);
- x1 = (0.0-b + d) / (2.0*a);
- x2 = (0.0-b - d) / (2.0*a);
- printf("%.2lf %.2lf\n", x1, x2);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。