求一元二次方程的解


#pragma warning(disable:4996)  
#include
#include
#include
#define EXP 0.00000001
float f = 0.00000001;
int main()
{
float a, b, c;
printf("Please Enter: ");
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;


}

你可能感兴趣的:(c语言)