Viết chương trình nhập vào 1 mảng số nguyên có n phần tử theo thứ tự giảm dần và số m. Chèn m vào mảng sao cho mảng vẫn có thứ tự giảm dần
Đáp Án:
var a:array[1..100] of integer;
n,m,i,j:integer;
begin
write('N=");readln(n);
for i:=1 to n do
begin
write('a[',i,']=');readln(a[i]);
end;
write('M=');readln(m);
write('Mang sau khi chen: ');
for i:=1 to n do
begin
if (m>=a[i]) and (j=0) then
begin
write(m,' ');
j:=1;
end;
write(a[i],' ');
end;
if j=0 then write(m);
readln;
end.