赞
踩
我稍微改了下。。。你试一下吧。。。
#include
#include
void main(){
float a,b,c,m,n;
float x,x1,x2,t;
printf("please input the number:\n");
scanf("%f%f%f",&a,&b,&c);
if (a==0){
if (b==0) printf("Input error!\n");
if (b!=0)
printf("x=%.6lf\n",-c/b);
}
if (a!=0) {
t=b*b-4*a*c;
//printf("t=%f\n",t);
if (t==0){
printf("x1=x2=%.6lf\n",-b/(2*a));
}
if (t>0){
x1=(-b+sqrt(t))/(2*a);
x2=(-b-sqrt(t))/(2*a);
printf("x1=%.6lf\n",x1);
printf("x2=%.6lf\n",x2);
}
if (t<0){
m=-b/(2*a);n=sqrt(-t)/(2*a);
printf("x1=%.6lf+%.6lfi\n",m,n);
printf("x1=%.6lf-%.6lfi\n",m,n);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。