cau 1)
rogram bai_tap;
uses crt;
var n,i:byte;
a:array[1..100] of real;
tb,s:real;
begin
clrscr;
write('nhap so luong phan tu cua mang: ');
readln(n);
for i:= 1 to n do
begin
write('A[',i,'] = ');
write(a[i]);
end;
s:=0;
for i:= 1 to n do
s:=s+a[i];
tb:= s/n;
write('so trung binh: ',tb:4:2);
readln
end;
cau3)
program bai_tap;
uses crt;
var n,i:byte;
b,chen:integer;
a:array[1..100] of integer;
begin
clrscr;
write('nhap so luong phan tu cua mang: ');
readln(n);
for i:= 1 to n do
begin
write('A[',i,'] = ');
write(a[i]);
end;
write('nhap gia tri can chen: ');
readln(chen);
write('nhap vi tri can chen: ');
readln(b);
for i:= n+1 downto b+1 do
a[i]:=a[i-1];
a[b]:=chen;
for i:= 1 to n+1 do
write(a[i]:4);
readln
end.
xóa cũng tương tụ kiểu như vậy
câu 4)
program bai_tap;
uses crt;
var n,i:byte;
k:integer;
a:array[1..100] of integer;
begin
clrscr;
write('nhap so luong phan tu cua mang: ');
readln(n);
for i:= 1 to n do
begin
write('A[',i,'] = ');
write(a[i]);
end;
write('nhap gia tri phan tu K: ');
readln(K);
for i:= 1 to n do
if a[i] = k then
begin
write('vi tri cua K la: ',i);
break; {vì tìm 1 phần tử}
end;
readln
end.
cau2)
program bai_tap;
uses crt;
var n,i:byte;
a:array[1..100] of real;
max,min::real;
begin
clrscr;
write('nhap so luong phan tu cua mang: ');
readln(n);
for i:= 1 to n do
begin
write('A[',i,'] = ');
write(a[i]);
end;
max:=a[1];min:=a[1];
for i:= 2 to n do
begin
if max < a[i] then max:=a[i];
if min > a[i] then min := a[i];
end;
write('gia tri max la: ',max:4:2,' gia tri min la: ',min:4:2);
readln
end;