8.2 C语言 简单 求方程的根

来源:百度知道 编辑:UC知道 时间:2024/07/07 00:43:55
#include <stdio.h>
#include<math.h>
main()
{float a,b,c,x1,x2,x,q;
float t(int a,int b,int c) ;
scanf("%d%d%d",&a,&b,&c);
while(b==0)
{printf("Once agine\n") ;
scanf("%d%d%d",&a,&b,&c);
}
if(a==0) x=-c/b; printf("%d\n",x);
else if (b*b-4*a*c>0)
{ x1=(-b-sqrt(b*b-4*a*c))/2a;
x2=(-b+sqrt(b*b-a*a*c))/2a;
printf("%d%d\n",x1,x2)
}
q=float t(int a,int b,int c);
printf("%d\n",q);
}
float t (int a,int b,int c)
{ int x
x=-b/2a;
return(x);
}

高手们 看看这次哪错了 我用 float t (int a,int b,int c)
只是想换种方法,没别的意思
请高手们在我的方法上改进 谢谢啊
这里是求 ax*x+bx+c=0的根

如果不考虑须根是这样的
#include <stdio.h>
#include<math.h>

main()
{float a,b,c,x1,x2,q,x;
float t(float a,float b);
scanf("%f %f %f",&a,&b,&c);

if(b*b-4*a*c<0)
printf("X1 and X2 not exsist\n");

if(a==0)
{
x=-c/b;
printf("x1=x2=%f\n",x);
}
else if (b*b-4*a*c>=0)
{ x1=(-b-sqrt(b*b-4*a*c))/2*a;
x2=(-b+sqrt(b*b-a*a*c))/2*a;
printf("x1=%f x2=%f\n",x1,x2);

q=t(a,b);
printf("-b/2a==%f\n",q);
}
}

float t(float a,float b)
{ float x;
x=-b/(2*a);
return x;
}
考虑有复根(虚数)的情况是这样的 只是把上面的稍做改动 就行 如下

#include <stdio.h>
#include<math.h>

main()
{float a,b,c,x1,x2,q,x;

float t(float a,float b);
scanf("%f %f %f",&a,&b,&c);

if(a=