共回答了22个问题采纳率:100%
#include
#include
// b^2-4ac == 0
void fun1(double &a,double &b,double &c,double &d){
double ans = -b/(2*a);
printf("b^2-4ac == 0 , x1 = x2 = %lf.n",ans);
}
// b^2-4ac > 0
void fun2(double &a,double &b,double &c,double &d){
double ans1,ans2;
ans1 = (-b+sqrt(d)) / (2*a);
ans2 = (-b-sqrt(d)) / (2*a);
printf("b^2-4ac > 0 , x1 = %lf , x2 = %lf.n",ans1,ans2);
}
// b^2-4ac < 0
void fun3(double &a,double &b,double &c,double &d){
double real,imar;
real = -b/(2*a);
imar = sqrt(-d) / (2*a);
printf("b^2-4ac < 0 , x1 = %lf+%lfi , x2 = %lf-%lfi.n",real,imar,real,imar);
}
int main(){
double a,b,c,d;
printf("please input a,b,c.n");
while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF){
d = b*b-4*a*c;
if(d==0) fun1(a,b,c,d);
else if(d>0) fun2(a,b,c,d);
else fun3(a,b,c,d);
printf("please input a,b,c.n");
}
}
1年前
1