1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| program gauss_elimination(input,output);
uses wincrt;
type mat= array[1..100,1..101];
sol=array[1..100];
var
n, m, L, k, G, i ,j: integer;
a, multi: mat;
x: sol;
temp, , s :real;
begin
writeln(give the number of equations n);
readln(n);
m:=n+1;
L:=n-1;
for i:=1 to n do
begin
for j:=1 to m do
begin
writeln('a[,i,j,']=);
readln(a[i,j]);
end;
end;
G:=k;
for k:=1 to L do
begin
if ( abs(a[i,k] ) > abs(a[G,k] ) ) then
G:= i
Else
Begin
For j:=k to m do
Begin
temp:=a[k,j];
a[k,j]:= a[G,j];
a[G,j]:= temp;
end;
end;
for i:=k+1 to n do
begin
multi[i,k]:= a[i,k]/ a[k,k];
for j:=k to m do
begin
a[i,j]: = a[i,j] (multi[i,k]* a[k,j]);
end;
end;
end;
end;
x[n]:=a[i,m]/ a[n,n];
for i:=n-1 downto 1 do
begin
s:=0;
for j:=i+1 to n do
begin
s:=s+a[i,j]*x[j];
end;
x[i]:=(1/a[i,i]) * (a[i,m] s );
end;
for i:=1 to n do
begin
writeln(the solutions for the system are x[i]=,x[i]);
readln(x[i]);
end;
end. |
Partager