例3.5 求ax^2+bx+c=0方程的根 a,b,c由键盘输入, b^2-4ac>=0

// 求ax^2+bx+c=0方程的根 

# include 
# include  

int main()
{
	double a,b,c,p,q,x1,x2;
	
	printf("请输入 a, b, c:\n");
	scanf("%lf %lf %lf",&a,&b,&c);
	
	p=-b/(2*a);
	q=sqrt(b*b-4*a*c)/(2*a);
	x1=p+q;
	x2=p-q;
	
	printf("x1=%7.2f\nx2=%7.2f\n",x1,x2);
	return 0; 
 } 

 

你可能感兴趣的:(C)