var a: array[1..MAX_SIZE] of integer; i, size: integer;
procedure delete_odd_elements(); var i, j: integer; begin i := 1; repeat if odd(a[i]) then begin dec(size); for j := i to size do a[j] := a[j + 1] end else inc(i); until i > size; end;
begin writeln('Исходный массив: '); size := MAX_SIZE; for i := 1 to size do begin a[i] := random(100); write(a[i] : 3); end; delete_odd_elements; writeln; writeln('Полученный массив: '); for i := 1 to size do write(a[i] : 3); end.
{ FreePascal 2.6.4}
program test;
uses
crt;
var
a, b, c, d : integer;
f : longint;
procedure swap (var x : integer; var y : integer);
var z : integer;
begin
z := x;
x := y;
y := z;
end;
function nod (m, n : integer) : integer;
begin
while m<>n do begin
if m>n
then
m:=m-n
else
n:=n-m;
end;
nod := m;
end;
function max (a,b : integer) : integer;
begin
if a>b
then max := a
else max := b;
end;
function min (x, y, z : integer) : integer;
var m : integer;
begin
m := x;
if y<m then m := y;
if z<m then m := z;
min := m;
end;
function mypow (a, b : integer) : integer;
var e, f : integer;
begin
f := 1;
for e:=1 to b do f := f*a;
mypow := f;
end;
function fact(a : integer) : longint;
var
i : integer;
res : longint;
begin
res := 1;
for i := 1 to a do res := res*i;
fact := res;
end;
begin
clrscr;
writeln('Test of function SWAP');
write('Input A: ');
readln(a);
write('Input B: ');
readln(b);
swap(a, b);
writeln('A=', a, ', B=', b);
writeln;
writeln('Test of function NOD');
write('Input A: ');
readln(a);
write('Input B: ');
readln(b);
c := nod(a, b);
writeln('NOD(', a, ',', b, ')=', c);
writeln;
writeln('Test of function MAX');
write('Input A: ');
readln(a);
write('Input B: ');
readln(b);
c := max(a, b);
writeln('MAX(', a, ',', b, ')=', c);
writeln;
writeln('Test of function MIN');
write('Input A: ');
readln(a);
write('Input B: ');
readln(b);
write('Input C: ');
readln(c);
d := min(a, b, c);
writeln('MIN(', a, ',', b, ',', c, ')=', d);
writeln;
writeln('Test of function POW');
write('Input A: ');
readln(a);
write('Input B: ');
readln(b);
c := mypow(a, b);
writeln('POW(', a, ',', b, ')=', c);
writeln;
writeln ('Test of function FACT (not large than 12!)');
write('Input A: ');
readln(a);
f := fact(a);
writeln(a, '!=', f);
writeln;
readkey;
end.
MAX_SIZE = 10;
var
a: array[1..MAX_SIZE] of integer;
i, size: integer;
procedure delete_odd_elements();
var i, j: integer;
begin
i := 1;
repeat
if odd(a[i]) then
begin
dec(size);
for j := i to size do
a[j] := a[j + 1]
end
else inc(i);
until i > size;
end;
begin
writeln('Исходный массив: ');
size := MAX_SIZE;
for i := 1 to size do
begin
a[i] := random(100);
write(a[i] : 3);
end;
delete_odd_elements;
writeln;
writeln('Полученный массив: ');
for i := 1 to size do
write(a[i] : 3);
end.