#include<stdio.h> #define P -b/(2*a) #define disc b*b-4*a*c #define Q sqrt(fabs(disc))/(2*a)
main() { float a,b,c,x1,x2,realpart,imagpart;
printf("Please input three limit :"); scanf("%f,%f,%f",&a,&b,&c); printf("The equation "); if(abs(disc)<=1e-6) { x1=x2=P; printf("has two equal roots : %8.4f .\n",x1); } else if(disc>0) { x1=P+Q; x2=P-Q; printf("has two distinct real roots : %8.4f , %8.4f .\n",x1,x2); } else { realpart=P; imagpart=Q; printf("has two complex roots : "); printf("%8.4f+%8.4fi\n",realpart,imagpart); printf(" "); printf("%8.4f-%8.4fi\n",realpart,imagpart); } getch(); } 上面的是对的 但是改成 if(fabs(disc)<=1e-6) 就不对了 fabs 不是对实数求绝对值吗? abs 是对正数求绝对值啊// 不是应该用 fabs 才对嘛?
----------------解决方案--------------------------------------------------------
不用回了 忘了加 #include<math.h>了
----------------解决方案--------------------------------------------------------
呵呵!看来细心才是最重要的!
----------------解决方案--------------------------------------------------------