作业帮 > 综合 > 作业

帮我看看求二次函数的C语言程序,要求要用函数来写,

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/04/27 21:41:01
帮我看看求二次函数的C语言程序,要求要用函数来写,
#include
#include
double t,x1,x2;
void main()
{
void situ1(double a,double b,double c);
void situ2(double a,double b,double c);
void situ3();
double x,a,b,c;
scanf("%lf%lf%lf",&a,&b,&c);
if (a=0)
x=c/b;
else
{
\x05t=b*b-4*a*c;
\x05if (t>0)
\x05\x05situ1(a,b,c);
\x05else if(t=0)
\x05\x05situ2(a,b,c);
\x05else
\x05\x05situ3();
\x05
}
}
void situ1(double a,double b,double c)
{
\x05x1=(-b+sqrt(t))/(2*a);
\x05x2=(-b-sqrt(t))/(2*a);
\x05printf("%lf\t%lf",x1,x2);
}
void situ2(double a,double b,double c)
{
\x05x1=x2=(-b+sqrt(t))/(2*a);
\x05printf("%lf\t%lf",x1,x2);
}
void situ3()
{
\x05printf("没有实根");
}
帮我看看求二次函数的C语言程序,要求要用函数来写,
我已经按你的意思修改了,也运行出来了,希望对你有帮助,代码附带在下面:
#include
#include
float t,x1,x2;
void main()
{
void situ1(float a,float b,float c);
void situ2(float a,float b,float c);
void situ3();
float x,a,b,c;
scanf("%f%f%f",&a,&b,&c);
if (a==0)
{
x=-c/b;
printf("x=%.2f\n",x);
}
else
{
t=b*b-4*a*c;
if (t>0)
situ1(a,b,c);
else if(t==0)
situ2(a,b,c);
else
situ3();
}
}
void situ1(float a,float b,float c)
{
x1=(-b+sqrt(t))/(2*a);
x2=(-b-sqrt(t))/(2*a);
printf("x1=%.2f\tx2=%.2f\n",x1,x2);
}
void situ2(float a,float b,float c)
{
x1=x2=(-b+sqrt(t))/(2*a);
printf("x1=x2=%.2f\n",x1);
}
void situ3()
{
printf("没有实根\n");
}