c 程序 实现一元二次方程

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

int main()

{ 
  double a,b,c,disc,x1,x2,p,q;

  scanf("%lf%lf%lf",&a,&b,&c);
  disc=b*b-4*a*c;

  if (disc<0)

     printf("This equation hasn't real roots\n");
  else

     {

       p=-b/(2.0*a);
       q=sqrt(disc)/(2*a);
       x1=p+q;
       x2=p-q;
       printf("real roots:\nx1=%7.2f\nx2=%7.2f\n",x1,x2);
     }
     return 0;
}
gcc delt.c -lm
./a.out 
100 5 2
This equation hasn't real roots
./a.out 
1 100 1
real roots:
x1=  -0.01
x2= -99.99

绝知此事要躬行

posted @ 2018-07-23 22:44  luoganttcc  阅读(195)  评论(0编辑  收藏  举报