解题思路:
注意事项:
参考代码:
#include<bits/stdc++.h>
using namespace std;
float delta_func(float a,float b,float c){
return pow(b,2.0)-4.0*a*c;
}
float left_func(float a,float b){
return -0.5*(b/a);
}
float right_func(float a, float sqrt_delta){
return sqrt_delta/(2.0*a);
}
int main(){
float a,b,c;
scanf("%f %f %f",&a,&b,&c);
float delta_val= delta_func(a,b,c);
float left_val = left_func(a,b);
if(delta_val>0){
float sqrt_delta_val = sqrt(delta_val);
float right_val=right_func(a,sqrt_delta_val);
printf("x1=%.3f+%.3f x2=%.3f-%.3f",left_val,right_val,left_val,right_val);
}
else if(delta_val==0){
float sqrt_delta_val=0;
//float right_val=right_func(a,sqrt_delta_val);
printf("x1=%.3f x2=%.3f",left_val,left_val);
}
else if(delta_val<0){
float sqrt_delta_val = sqrt(-delta_val);
float right_val=right_func(a,sqrt_delta_val);
printf("x1=%.3f+%.3fi x2=%.3f-%.3fi",left_val,right_val,left_val,right_val);
}
return 0;
}
0.0分
0 人评分