解题思路:





注意事项:写代码要仔细,要仔细,要仔细!!重要的事情说三遍!





参考代码:

#include<stdio.h>

#include<math.h>

double fun1(double,double,double);

double fun2(double,double,double);

main()

{

double a,b,c;

scanf("%lf %lf %lf",&a,&b,&c);

  if(b*b-4*a*c>0)  

  {

 printf("x1=%.3f+%.3f ",fun1(a,b,c),fun2(a,b,c));

      printf("x2=%.3f-%.3f\n",fun1(a,b,c),fun2(a,b,c));

  }

 if(b*b-4*a*c==0)

 {

printf("x1=%.3f+%.3f ",fun1(a,b,c),fun2(a,b,c));

      printf("x2=%.3f-%.3f\n",fun1(a,b,c),fun2(a,b,c));

 }

 if(b*b-4*a*c<0)

 {

printf("x1=%.3f+%.3fi ",fun1(a,b,c),fun2(a,b,c));

      printf("x2=%.3f-%.3fi\n",fun1(a,b,c),fun2(a,b,c));

 }

}

double fun1(double m,double n,double k)

{

double x;

x=((-1)*n)/(2*m);

   return x;

}


double fun2(double m,double n,double k)

{

double x1,x2;

x1=sqrt(n*n-4*m*k)/(2*m);

x2=sqrt(4*m*k-n*n)/(2*m); 

if(n*n-4*m*k>=0)

       return x1;

return x2;

}


 

0.0分

0 人评分

  评论区

  • «
  • »