# 36.求一元二次方程的根(36. Find the root of a quadratic equation of one variable)-其他

## 36.求一元二次方程的根(36. Find the root of a quadratic equation of one variable)

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

/*浮点数比较大小往往判断绝对值是否小于一个要求的精度 */ int main(){ double a,b,c,d; printf(“请输入一元二次方程组的3个系数：”); scanf(“lf%lf%lf”,&a,&b,&c); if(fabs(a-0)<=1e-6){ printf(“输入有误，程序结束运行\n”); return 0; } d=b*b-4*a*c; if(d<0) printf(“此方程无实数根\n”); else if(fabs(d)<=1e-6) printf(“此方程的根为%lf\n”,-b/(2*a)); else printf(“此方程的两个根为%lf,%lf\n”,(-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a)); return 0; }

————————

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

/*Comparing the size of floating-point numbers often determines whether the absolute value is less than a required precision * / int main(){ double a,b,c,d; Printf (“please input three coefficients of a system of quadratic equations in one variable:”); scanf(“lf%lf%lf”,&a,&b,&c); if(fabs(a-0)<= 1e-6){ Printf (“input error, program ends running \ n”); return 0; } d=b*b-4*a*c; if(d<0) Printf (“this equation has no real roots \ n”); else if(fabs(d)<= 1e-6) Printf (“the root of this equation is% LF \ n”, – B / (2 * a)); else Printf (“the two roots of this equation are% LF,% LF \ n”, (- B + sqrt (d)) / (2 * a), (- b-sqrt (d)) / (2 * a)); return 0; }