题解 | #计算一元二次方程#
计算一元二次方程
https://www.nowcoder.com/practice/7da524bb452441b2af7e64545c38dc26
#include <stdio.h> #include<math.h> int main() { float a, b,c,sum,x,y,x1,y1; while (scanf("%f %f %f", &a, &b,&c) != EOF) { if(a==0) { printf("Not quadratic equation\n"); } else { sum=pow(b,2)-4*a*c; x=(-b+sqrtf(sum))/(2.0*a); y=(-b-sqrtf(sum))/(2.0*a); if(sum==0&&x!=0) { printf("x1=x2=%.2f\n",x); } else if(sum==0&&x==0) { printf("x1=x2=0.00\n"); } else if(sum>0) { printf("x1=%.2f;x2=%.2f\n",y,x); } else if(sum<0) { printf("x1=%.2f-%.2fi;x2=%.2f+%.2fi\n",-b/(2*a),sqrt(-sum)/(2*a),-b/(2*a),sqrt(-sum)/(2*a)); } } } return 0; }#日常c语言练习#