//一元二次方程求解 //重复执行,直到按ctrl+D或ctrl+E 结束 // #include<math.h> #include<stdio.h> #include<stdlib.h> int main(){ float a,b,c,x1,x2; float delta,real,imag; printf("Enter a,b,c:"); while(scanf("%f%f%f",&a,&b,&c)){ if(a==0) printf("not quadratic equation.\n"); else{ delta=b*b-4*a*c; if(delta>=0){ x1=(-b+sqrt(delta))/(2*a); x2=(-b+sqrt(delta))/(2*a); printf("x1=%f,x2=%f\n",x1,x2); } else{ real=-b/(2*a); imag=sqrt(-delta)/(2*a); printf("x1=%f+%fi,x2=%f-%fi\n",real,imag,real,imag); } } printf("Enter a,b,c:\n"); } system("pause"); return 0; }
原文:https://www.cnblogs.com/201qx/p/11878357.html