22.
xwizard
(15.12.2009 18:07)
0
program Shell; var k,i,j,d: integer; a: array [1..20] of integer; begin
writeln(''Massiv:''); for i:=1 to 20 do begin a[i]:=-13+random(54); write(a[i],'' ''); end; d:=0; k:=0; repeat if (k=0) and (d=3) then d:=1; if (k=0) and (d=5) then d:=3; if (k=0) and (d=0) then d:=5; k:=0; for i:=1 to 20-d do if a[i]>a[i+d] then begin j:=a[i]; a[i]:=a[i+d]; a[i+d]:=j; k:=1; end; until (d=1) and (k=0);
writeln; writeln(''Result:''); for i:=1 to 20 do write(a[i],'' '');
readln; end.
program Sheiker; var i,j,z,k: integer; a: array [1..20] of integer; begin writeln(''Massiv:''); for i:=1 to 20 do begin a[i]:=-2+random(34); write(a[i],'' ''); end;
z:=1; repeat k:=0; if z mod 2 <> 0 then begin
for i:=1 to 20-z do if a[i]>a[i+1] then begin j:=a[i]; a[i]:=a[i+1]; a[i+1]:=j; k:=1; end;
end else begin
for i:=20 downto z do if a[i]<a[i-1] then begin j:=a[i]; a[i]:=a[i-1]; a[i-1]:=j; k:=1; end; end;
z:=z+1; until k=0;
writeln(''Resultat:'');
for i:=1 to 20 do write(a[i],'' '');
end.
program MetGA; var a: array [1..4, 1..4] of double; b,x: array [1..4] of double; i,j,k: integer; s: double; begin a[1,1] := 5.7; a[1,2] := -7.8; a[1,3] := -5.6; a[1,4] := -8.3; a[2,1] := 6.6; a[2,2] := 13.1; a[2,3] := -6.3; a[2,4] := 4.3; a[3,1] := 14.7; a[3,2] := -2.8; a[3,3] := 5.6; a[3,4] := -12.1; a[4,1] := 8.5; a[4,2] := 12.7; a[4,3] := -23.7; a[4,4] := 5.7;
b[1] := 2.7; b[2] := -5.5; b[3] := 8.6; b[4] := 14.7;
for k:=1 to 3 do for i:=k+1 to 4 do for j:=1 to 4 do begin a[i,j] := a[i,j] - (a[i,k]*a[k,j])/a[k,k]; b[i] := b[i] - (a[i,k]*b[k])/a[k,k]; end;
for i:=1 to 4 do begin for j:=1 to 4 do write(a[i,j]:2:3,'' ''); writeln; end;
x[4]:=b[4]/a[4,4];
for i := 3 downto 1 do begin s := 0.0;
for j := i+1 to 4 do s := s + a[i,j] * x[j];
x[i] := (b[i] - s) / a[i,i]; end;
writeln(''Resultat:''); for i:=1 to 4 do writeln(x[i]:3:3);
for i:=1 to 4 do begin s:=0; for j:=1 to 4 do s:=s+a[i,j]*x[j]; writeln((s-b[i]):3:3); end;
readln; end.
|