Ví dụ:
Mã: Chọn tất cả
Moi ban nhap vao so N: 5
Moi ban nhap lan luot cac so: 2 4 6 8 10
Moi ban nhap vi tri cua phan tu can chen vao: 3
Moi ban nhap gia tri: 9
Day so moi la: 2 4 9 6 8 10
Moi ban nhap vi tri cua phan tu can xoa: 3
Day so moi la: 2 4 6 8 10
Mã: Chọn tất cả
Uses Crt;
Var N, i, k : Integer;
M : Array[1..100] Of Integer;
Begin
ClrScr;
N := 0;
While ((N < 5) Or (N > 10)) Do
Begin
Write('Moi ban nhap vao so N: ');
ReadLn(N);
End;
Write('Moi ban nhap lan luot cac so: ');
For i := 1 To N Do Read(M[i]);
ReadLn;
k := 0;
While ((k < 1) Or (k > N)) Do
Begin
Write('Moi ban nhap vi tri cua phan tu can chen vao: ');
ReadLn(k);
End;
For i := N DownTo k Do M[i+1] := M[i];
Write('Moi ban nhap gia tri: ');
ReadLn(i);
M[k] := i;
Inc(N);
Write('Day so moi la: ');
For i := 1 To N Do Write(M[i], ' ');
k := 0;
While ((k < 1) Or (k > N)) Do
Begin
Write('Moi ban nhap vi tri cua phan tu can xoa: ');
ReadLn(k);
End;
For i := k+1 To N Do M[i-1] := M[i];
Dec(N);
Write('Day so moi la: ');
For i := 1 To N Do Write(M[i], ' ');
ReadLn;
End.