求二元一次方程组x,y值。帮小弟看看有问题不? 小弟刚学到do..while循环,谢谢大神们
/*当a/d≠b/e 时,该方程组有一组解。 当a/d=b/e=c/f 时,该方程组有无数组解。 当a/d=b/e≠c/f 时,该方程组无解。*/#include <stdio.h>
int main(void)
{
char ch;
double a,b,c,d,e,f,x,y,n,p,w,z,i,v;
do
{
printf("\n");
printf("\n");
printf("求二元一次方程ax+by+c=0\n");
printf(" dx+ey+f=0的值\n");
printf("\n");
printf("\n");
x = 0; //把x的值初始化一下
y = 0; //把y的值初始化一下
n = 0;
p = 0;
w = 0;
z = 0;
printf("请输入a的值:");
scanf ("%lf",&a);
printf("a = %lf\n",a);
printf("请输入b的值:");
scanf ("%lf",&b);
printf("b = %lf\n",b);
printf("请输入c的值:");
scanf ("%lf",&c);
printf("c = %lf\n",c);
printf("请输入d的值:");
scanf ("%lf",&d);
printf("d = %lf\n",d);
printf("请输入e的值:");
scanf ("%lf",&e);
printf("e = %lf\n",e);
printf("请输入f的值:");
scanf ("%lf",&f);
printf("f = %lf\n",f);
printf ("表达式一为:%lf*x+%lf*y+%lf=0\n",a,b,c);
printf ("表达式二为:%lf*x+%lf*y+%lf=0\n",d,e,f);
n = (d*c) - (a*f);
p = (a*e) - (b*d);
y = 1.0*n/p;
w = (b*f)-(c*e);
z = (a*e)-(b*d);
x = 1.0*w/z;
if (a==0 && b==0)
{
printf ("表达式不成立,此方程组错误!\n");
}
else if (d==0 && e==0)
{
printf ("表达式不成立,此方程组错误!\n");
}
else if ((1.0*a/d ==1.0*b/e) && (1.0*a/d != 1.0*c/f))
printf ("此方程式无解!\n");
else if (1.0*a/d == 1.0*b/e == 1.0*c/f)
printf ("此方程式有无数个解!\n");
else if (a==0 && d==0)
{
double m,t;
m = 1.0*b/e;
t = 1.0*c/f;
if (m==t)
{
y = -1.0*c/b;
printf ("x=x任意值,y= %lf\n",y);
}
else
printf ("无解!\n");
}
else if (b==0 && e==0)
{
double m,t;
m = 1.0*a/d;
t = 1.0*c/f;
if (m==t)
{
x = -1.0*c/a;
printf ("x= %lf,y取任意值\n",x);
}
else
printf ("无解!\n");
}
else if (1.0*a/d != 1.0*b/e)
{
y = 1.0*n/p;
x = 1.0*w/z;
printf ("x = %lf,y = %lf \n",x,y);
}
else
printf ("此方程真的无解!\n");
printf ("你想继续么(y/n):");
scanf (" %c",&ch); //取字符时,%c前面要有空格
} while ('y' == ch || 'Y'== ch);
return 0;
}