#include<stdio.h>
#include<math.h>
main()
{
void more(float a,float b,float c);
void equal(float a,float b,float c);
void below(float a,float b,float c);
float a,b,c,disc;
scanf("%f %f %f",&a,&b,&c);
disc=b*b-4*a*c;
if(fabs(a)<=1e-6) //注意表示方式:接近0用1e-6表示哦。此时不是一元二次方程
printf("error\n");
if(disc>1e-6) //大于0--两个根
more(a,b,c);
if(fabs(disc)<=1e-6) //两个相同根
equal(a,b,c);
if(disc<0) //两个共轭根
below(a,b,c);
}
void more(float a,float b,float c)
{
float y=(-b)/2*a,disc=b*b-4*a*c;
printf("is %f and %f\n", y+sqrt(disc)/(2*a),y-sqrt(disc)/(2*a));
}
void equal(float a,float b,float c)
{
printf("is %f\n",(-b)/(2*a));
}
void below(float a,float b,float c)
{
float y=(-b)/(2*a),disc=b*b-4*a*c;
printf("is %f and %f\n",y+sqrt(-disc)/(2*a),y-sqrt(-disc)/(2*a));
}
Programación en la ecuación de la raíz de la función de búsqueda del lenguaje C (discutido en cuatro casos)
Supongo que te gusta
Origin blog.csdn.net/September_C/article/details/105447332
Recomendado
Clasificación