3_2二次方程求根
Time Limit:1000MS Memory Limit:65536K
Total Submit:10179 Accepted:2477
Description
输入参数a、b、c,求一元二次方程ax2+bx+c=0的根。
Input
三个实数a、b、c,并确保Δ≥0。
Output
方程两个实根,保留两位小数。
Sample Input
1 2 -8
Sample Output
x1=2.00 x2=-4.00
Source
#include<stdio.h>
#include<math.h>
int main()
{
double a, b, c;
double x1, x2, d=0;
scanf("%lf %lf %lf", &a, &b, &c);
d = sqrt(pow(b,2)- 4.0 * a * c);
x1 = (-b + d) / (2.0 * a);
x2 = (-b - d) / (2.0 * a);
printf(“x1=%.2f x2=%.2f”, x1, x2);
return 0;
}