C语言求一元二次函数的解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chen739481102/article/details/52971840
#include <stdio.h>
#include <math.h>
int main()
{
float a=0;
float b=3;
    float c=2;
float x1,x2;
float m=b*b-4*a*c;
if(a==0)
{
x1=-(c/b);
   printf("该函数不是一元二次函数\n");
printf("x = %lf\n",x1);
}
else
{
 if(m==0)
 {
 printf("该函数有两个相等的根");
          x1=x2=((-b)+sqrt(m))/(2*a);
 }
 else if(m<0)
 {
   printf("该函数有两个共轭根\n");
 }
 else
 {
   printf("该函数有两个不相等的根\n");
x1=((-b)+sqrt(m))/(2*a);
x2=((-b)-sqrt(m))/(2*a);
printf("x1 = %lf  x2 = %lf",x1,x2);
 }
}


    return 0;
}

猜你喜欢

转载自blog.csdn.net/chen739481102/article/details/52971840