#includestdio h" #include"math. h' oid main( float a, b, c, p, xl, x 2, real, imag: printi(请输入一元二次方程的三个系数:”) scanf("%f%f%f", &a, &b, &c) if(a==0&&b!=0) printi("方程有一个根:%fn"-cb), else if(a!=0) p=b*b-4*a*c real=-b/(2*a) imag=sqrt(fabs(p))/(2a) if(p==0) printf("方程有一个根:%fn",rea) else if(p<0) printi("方程有两个共轭复根:mn") %8f+%fiin"real, imag) printf("%8f-%fi\", real, imag) x1=real+imag, printf("程有两个实根:n") printf("%1Of and %f\n, x1, x2 printi("非法输入或无意义!in");
#include"stdio.h" #include"math.h" void main() { float a,b,c,p,x1,x2,real,imag; printf(“请输入一元二次方程的三个系数:”); scanf("%f%f%f",&a,&b,&c); if(a==0 &&b!=0) printf("方程有一个根:%f\n",-c/b); else if(a!=0) { p=b*b-4*a*c; real=-b/(2*a); imag=sqrt(fabs(p))/(2*a); if(p==0) printf("方程有一个根:%f\n",real); else if(p<0) { printf("方程有两个共轭复根:\n"); printf("%8f+%fi\n",real,imag); printf("%8f-%fi\n",real,imag); } else { x1=real+imag; x2=real-imag; printf("方程有两个实根:\n"); printf("%10f and %f\n",x1,x2); } } else printf("非法输入或无意义!\n"); }