跪求大神救我
pascal吧
全部回复
仅看楼主
level 2
我们假定二元一次方程组的一般格式如下:(a,b,c,d,e,f为常数,x,y为未知数)
    ax+by=c
    dx+ey=f
  程序读入a,b,c,d,e,f后,输出解。
  当然,方程组也有可能存在无解或有无穷解的情况:如果(x,y)没有相对应的实数对满足方程组则无解;相反,如果(x,y)有多组对应的实数对满足方程组则有无数解。
  如果无解,就输出“No answer”;如果有无穷解,就输出“Too many”。
输入仅1行,包含6个整数,a,b,c,d,e,f。如果有解,那么第1行先输出“x=”,再输出x的值,第2行先输出“y=”,再输出y的值,均保留2位小数,请参照样例输出。
  如果无解或有无数解则按要求输出“No answer”或“Too many”。
未成功代码:
var
a,b,c,d,e,f,x,y:real;
begin
while not eof do begin
readln(a,b,c,d,e,f);
if (a*e-b*d=0) and ((c*e-b*f<>0) or (a*f-c*d<>0)) then writeln('No answer')
else if (c*e-b*f=0) or (a*f-c*d=0) then writeln('Too many')
else begin
y:=(a*f-c*d)/(a*e-b*d);
x:=(b*d-a*e)/(f*b-c*e);
writeln('x=',x:0:2);
writeln('y=',y:0:2);
end;
end;
end.
2014年06月23日 12点06分 1
level 11
使用高斯消元多简单...
2014年06月30日 09点06分 2
level 12
1.不需要while not eof那句……
2.第一个if-else的逻辑关系不对…
3.用行列式的解的公式也有误……
2014年06月30日 13点06分 3
level 2
var
a,b,c,d,e,f,a1,b1,c1,d1,e1,f1:longint;
x,y:real;
begin
while not eof do begin
readln(a,b,c,d,e,f);
a1:=a*e;
c1:=c*e;
d1:=b*d;
f1:=c*d;
a1:=d1-a1;
c1:=f1-c1;
if (a1=0) and (c1=0) then begin
writeln('Too many');
exit;
end;
if (a1=0) and (c1<>0) then begin
writeln('No answer');
exit;
end;
x:=(f*b-c*e)/(b*d-a*e);
b1:=c*d;
c1:=c*e;
e1:=b*d;
f1:=b*f;
b1:=b1-e1;
c1:=c1-f1;
if (b1=0) and (c1=0) then begin
writeln('Too many');
exit;
end;
if (b1=0) and (e1<>0) then begin
writeln('No answer');
exit;
end;
y:=(a*f-c*d)/(a*e-b*d);
writeln('x=',x:0:2);
writeln('y=',y:0:2);
end;
end.
这样就可以啦。。
2014年07月01日 04点07分 4
写的比高斯消元解n个方程都长了
2014年07月04日 13点07分
1