0 bình luận về “Nhập mảng và in ra phần tử xuất hiện trên 2 lần”
uses crt; var n,i,j,d,k,tam,l,kt:longint;a,b:array[1..100]of longint; begin clrscr; readln(n); for i:=1 to n do readln(a[i]); for i:=1 to n do begin d:=0; for j:=1 to n do if a[i]=a[j] then inc(d); if(d>1)then begin for l:=1 to k do if(a[i]=b[l])then kt:=1; if(kt=0)then begin inc(k);b[k]:=a[i];end; end; end; for i:=1 to k do write(b[i],’ ‘); readln; end.
uses crt;
var n,i,j,d,k,tam,l,kt:longint;a,b:array[1..100]of longint;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
for i:=1 to n do
begin
d:=0;
for j:=1 to n do
if a[i]=a[j] then inc(d);
if(d>1)then begin
for l:=1 to k do
if(a[i]=b[l])then kt:=1;
if(kt=0)then begin inc(k);b[k]:=a[i];end;
end;
end;
for i:=1 to k do
write(b[i],’ ‘);
readln;
end.
program xuathien;
uses crt;
var A:array[1..100] of integer;
n,i,j:integer;
begin
clrscr;
write(‘Nhap so luong phan tu cua day: ‘); readln(n);
writeln(‘NHAP GIA TRI TUNG PHAN TU CUA DAY’);
for i:=1 to n do
begin
write(‘phan tu thu ‘,i,’: ‘);
readln(A[i]);
end;
for i:=1 to n do
begin
B[i]:=1;
for j:=i+1 to n do
if A[i]=A[j] then B[i]:=B[i]+1;
end;
for i:=1 to n do
if B[i]>=2 then write(‘A[i],’ ‘);
readln
end.