Skip to content

Instantly share code, notes, and snippets.

@drage0
Last active April 25, 2016 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drage0/710105db0c8ed047c1e8a4350576611b to your computer and use it in GitHub Desktop.
Save drage0/710105db0c8ed047c1e8a4350576611b to your computer and use it in GitHub Desktop.
PROGRAM z45;
TYPE niz = ARRAY[1..100] OF integer;
VAR
x, y : niz;
n, i, j : integer;
PROCEDURE unos(n: integer; var x: niz);
VAR i: integer;
BEGIN
FOR i:=1 TO n DO
BEGIN
write('x[', i, ']=');
readLn(x[i]);
END;
END;
PROCEDURE stampa(n: integer; x: niz);
VAR i: integer;
BEGIN
FOR i:=1 TO n DO
BEGIN
writeLn('x[', i, ']=', x[i]);
END;
END;
PROCEDURE RAZ(var x,y: integer);
BEGIN
IF(x > y) THEN
BEGIN
x := x + y;
y := x - y;
x := x - y;
END
ELSE
BEGIN
y := y + x;
x := y - x;
y := y - x;
END;
END;
{ i KAPPA}
{ 1 4 5 2 8 4 }
PROCEDURE bs(n: integer; VAR x: niz);
VAR
i, j: integer;
k: boolean;
BEGIN
i := n-1;
k := false;
WHILE((not k) and (i > 1)) DO
BEGIN
k := true;
FOR j:=1 TO i DO
BEGIN
IF(x[j] > x[j+1]) THEN
BEGIN
raz(x[j], x[j+1]);
k := false;
END;
END;
i := i - 1;
END;
END;
FUNCTION iz_n(n: integer): boolean;
BEGIN
IF(n > 0) THEN iz_n := true
ELSE iz_n := false;
END;
BEGIN
write('n=');
readLn(n);
unos(n, x);
j := 0;
FOR i:=1 TO n DO
BEGIN
IF(iz_n(x[i])) THEN
BEGIN
j := j+1;
y[j] := x[i];
END;
END;
bs(j, y);
writeLn('--------');
stampa(j, y);
readLn();
END.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment