next up previous contents
Next: Bibliography Up: Листинги программ Previous: Листинги программ   Contents


Гаусс

program gauss;

const nn=1000;

var

a : array [1..nn,1..nn] of double;

x,b : array [1..nn] of double;

n,i,j,k : integer;

d : double;

begin

write('Enter n:');

read(n);

for i:=1 to n do

begin

for j:=1 to n do

begin

write('a[',i:3,',',j:3,']:');

read (a[i,j]);

end;

end;

for i:=1 to n do

begin

write('b[',i:3,']:');

read (b[i]);

end;

for i:=1 to n-1 do

begin

for k:=i+1 to n do

begin

d:=a[k,i]/a[i,i];

for j:=i+1 to n do

a[k,j]:=a[k,j]-a[i,j]*d;

b[k]:=b[k]-b[i]*d;

end;

end;

for i:=n downto 1 do

begin

for j:=i+1 to n do

b[i]:=b[i]-a[i,j]*x[j];

x[i]:=b[i]/a[i,i];

end;

for i:=1 to n do

writeln('x[',i:3,']=',x[i]:1:5);

end.



Eugene Misnik 2005-07-29