program GiaoTapHop;
const
MAX_SIZE = 100;
var
A, B, GiaoTapHop: array[1..MAX_SIZE] of integer;
sizeA, sizeB, sizeGiao: integer;
i, j, element: integer;
found: boolean;
procedure NhapMang(var arr: array of integer; var size: integer);
var
i: integer;
begin
write('Nhap kich thuoc mang: ');
readln(size);
writeln('Nhap cac phan tu cua mang:');
for i := 1 to size do
begin
repeat
write('Phan tu ', i, ': ');
readln(element);
found := false;
for j := 1 to i - 1 do
begin
if arr[j] = element then
begin
writeln('Phan tu da ton tai trong mang. Nhap lai.');
found := true;
break;
end;
end;
until not found;
arr[i] := element;
end;
end;
procedure TimGiaoTapHop(A, B: array of integer; sizeA, sizeB: integer; var GiaoTapHop: array of integer; var sizeGiao: integer);
var
i, j: integer;
begin
sizeGiao := 0;
for i := 1 to sizeA do
for j := 1 to sizeB do
if A[i] = B[j] then
begin
sizeGiao := sizeGiao + 1;
GiaoTapHop[sizeGiao] := A[i];
end;
end;
procedure InMang(arr: array of integer; size: integer);
var
i: integer;
begin
writeln('Cac phan tu cua mang la:');
for i := 1 to size do
write(arr[i], ' ');
writeln;
end;
begin
NhapMang(A, sizeA);
NhapMang(B, sizeB);
TimGiaoTapHop(A, B, sizeA, sizeB, GiaoTapHop, sizeGiao);
writeln('Cac phan tu la giao cua hai tap hop:');
InMang(GiaoTapHop, sizeGiao);
end.