Đề bài 1:
uses crt;
var a,b,c:array[1..100]of integer;
k,i,n,max,min,dem,dem1,tam,j,dem2,t:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('nhap k='); readln(k);
{-------------------------------cau-a--------------------------}
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('gia tri lon nhat cua mang la: ',max);
dem:=0;
for i:=1 to n do
if max=a[i] then
begin
inc(dem);
b[dem]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem do
write(b[i]:4);
{-----------------------------cau-b--------------------------}
writeln;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('gia tri nho nhat cua mang la: ',min);
dem1:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem1);
c[dem1]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem1 do
write(c[i]:4);
{--------------------------cau-c------------------------}
writeln;
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+sqr(a[i]);
writeln('tong binh phuong cac phan tu o vi tri chan la: ',t);
{------------------------cau-d-------------------------------}
writeln('mang duoc sap xep tang dan la: ');
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
for i:=1 to n do
write(a[i]:4);
{------------------------cau-e-----------------------}
writeln;
dem2:=0;
for i:=1 to n do
if a[i]=k then inc(dem2);
writeln('so gia tri bang ',k,' trong day la: ',dem2);
readln;
end.
Đề bài 2:
uses crt;
var a:array[1..100]of integer;
n,i,dem,dem1,t,t1,t2:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------cau-a--------------------------}
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('so luong so chan co trong mang la: ',dem);
{-------------------------------cau-b---------------------------}
dem1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then inc(dem1);
writeln('so luong so le co trong mang la: ',dem1);
{-----------------------------cau-c--------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('tong cac so chan co trong mang la: ',t);
{------------------------------cau-d--------------------------}
t1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t1:=t1+a[i];
writeln('tong cac so le co trong mang la: ',t1);
{------------------------------cau-e-------------------------}
t2:=0;
for i:=1 to n do
t2:=t2+a[i];
writeln('gia tri trung binh cua mang la: ',t2/n:4:2);
readln;
end.