+0和-0不一样的情况要改3处,
//
// Created by Administrator on 2023/4/5.
//
#include <cstdio>
#include <cmath>
void equation(float a, float b, float c){
if(a == 0){//a==0情况
printf("Not quadratic equation\n");
}else{//a≠0情况
float zelta = b*b - 4*a*c;
float answer, answer1, answer2;
if(zelta == 0){
answer = 0.5*(b*(-1)+sqrt(zelta))/a;
float mp = -b + sqrt(zelta);
if(mp == 0){//这个改动,+0和-0,不一样
printf("x1=x2=%.2f\n", mp);
}else{
printf("x1=x2=%.2f\n", answer);
}
}else if(zelta > 0){
answer1 = 0.5*(b*(-1)-sqrt(zelta))/a;
answer2 = 0.5*(b*(-1)+sqrt(zelta))/a;
printf("x1=%.2f;x2=%.2f\n", answer1, answer2);
}else{//zelta小于0
float shibu, xubu;
shibu = -1*b/(2*a);
xubu = sqrt(-1*zelta)/(2.0*a);
if(shibu == -0){//+0和-0不一样
shibu *= -1;
}
if(xubu <= -0){//+0和-0不一样
xubu *= -1;
}
printf("x1=%.2f-%.2fi;x2=%.2f+%.2fi\n", shibu, xubu, shibu, xubu);
}
}
}
int main(){
float a, b, c;
while (scanf("%f %f %f", &a, &b, &c) != EOF){
equation(a, b, c);
}
return 0;
}