program Mang;
uses crt;
var a:array[1..100] of integer;
x,i,n,j,temp:integer;
begin clrscr;
write('Nhap n = '); readln(n);
for i:=1 to n do
begin
write('a[',i,']= '); readln(a[i]);
end;
for i:=1 to n do
for j:=i+1 to n do
if (a[i] < a[j]) then
begin
temp := a[i];
a[i] := a[j];
a[j] := temp;
end;
for i:=1 to n do
writeln(a[i]);
write('Nhap x = '); readln(x);
a[n+1] := x;
for i:=1 to n+1 do
for j:=i+1 to n+1 do
if (a[i] < a[j]) then
begin
temp := a[i];
a[i] := a[j];
a[j] := temp;
end;
for i:=1 to n+1 do
writeln(a[i]);
readln;
end.
Câu 5:
uses crt;
var s,st:string;
a:array[1..255]of string;
i,d,dem,kt,j,dem1:integer;
begin
clrscr;
write('Nhap xau:'); readln(s);
st:=''
for i:=1 to length(s) do
if (s[i] in ['a'..'z']) or (s[i] in ['A'..'Z']) then st:=st+s[i];
d:=length(st);
dem:=1;
a[1]:=st[1];
for i:=1 to d do
begin
kt:=0;
for j:=1 to dem do
if a[j]=st[i] then kt:=1;
if kt=0 then
begin
inc(dem);
a[dem]:=st[i];
end;
end;
for i:=1 to dem do
begin
dem1:=0;
for j:=1 to d do
if a[i]=st[j] then inc(dem1);
writeln(a[i],' xuat hien ',dem1,' lan');
end;
readln;
end.
Câu 4:
uses crt;
var a:array[1..100]of integer;
i,n,d:integer;
kt:boolean;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
d:=abs(a[2]-a[1]);
kt:=true;
for i:=2 to n do
if abs(a[i]-a[i-1])<>d then
begin
kt:=false;
break;
end;
if kt=true then writeln('Day la cap so cong')
else writeln('Day khong la cap so cong');
readln;
end.