解题思路:参考大佬的,费劲了千辛万苦总算写出来了
注意事项:我还没注意。。。提醒大家,函数原型记得要写,并且记得加;(分号)!!!!
参考代码:
#include <stdio.h>
#include <math.h>
void girl_1(double a,double b,double c);
void girl_2(double a,double b,double c);
void girl_3(double a,double b,double c);
int main(void)
{
double a,b,c;
double x1,x2;
scanf("%lf %lf %lf",&a,&b,&c);
double test=b*b-4*a*c;
int number;
if(test>0)
girl_1(a,b,c);
else if(test==0)
girl_2(a,b,c);
else number=3;
girl_3(a,b,c);
return 0;
}
void girl_1(double a,double b,double c)
{
double x1,x2;
double test=sqrt(b*b-4*a*c);
double part=sqrt(b*b-4*a*c);
x1=(-b+part)/(2*a);
x2=-(b+part)/(2*a);
printf("x1=%.3lf x2=%.3lf",x1,x2);
}
void girl_2(double a,double b,double c)
{
double x1,x2;
x1=x2=(-b)/(2*a);
printf("x1=%.3 lf x2=%.3lf",x1,x2);
}
void girl_3(double a,double b,double c)
{
double test=sqrt(4*a*c-b*b);
double Re=(-b)/(2*a);
printf("x1=%.3lf+%.3lfi x2=%.3lf-%.3lfi",Re,test/(2*a),Re,test/(2*a));
}
0.0分
0 人评分