求一元二次方程的解

时间:2021-09-24 00:01:40
#pragma warning(disable:4996)  
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define EXP 0.00000001
float f = 0.00000001;
int main()
{
float a, b, c;
printf("Please Enter<ax^2 + bx + c = 0>: ");
scanf("%f%f%f", &a, &b, &c);


if (a > -EXP && a < EXP){
printf("不是一元二次方程!\n");
}
else{
float d = b*b - 4 * a*c;
if (d > -EXP && d < EXP){
printf("解: %f\n", -b / (2 * a));
}
else if (d > EXP){
printf("解: %f, %f\n", \
(-b + sqrt(d)) / (2 * a), \
(-b - sqrt(d)) / (2 * a));
}
else{
printf("无解!\n");
}
}
system("pause");
return 0;


}