uses crt; var i,n,j,t:integer; a:array[0..100] of integer; BEGIN clrscr; write(‘Nhap n:’); readln(n); for i:=1 to n do begin write(‘Nhap a[‘,i,’]’); readln(a[i]); end; for i:=1 to n-1 do for j:=i+1 to n do if a[j]<=a[i] then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end; write(‘Mang sau khi da sap xep:’); for i:=1 to n do write(a[i],’ ‘); readln END.
hơi dài nhưng rất là chính xác nha! và câu lệnh cũng rất dễ hiểu
program tangdan;
var A:array[1..10000] of integer;
n,i,tg,j:integer;
begin
clrscr;
write(‘Nhap so luong phan tu n: ‘); readln(n);
writeln(‘NHAP GIA TRI TUNG PHAN TU CUA MANG’);
for i:=1 to n do
begin
write(‘A[‘,i,’]= ‘);
readln(A[i]);
end;
writeln(‘DAY VUA NHAP LA:’);
for i:=1 to n do
write(A[i],’ ‘);
writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if A[i]>A[j] then
begin
tg:=A[i];
A[i]:=A[j];
A[j]:=tg;
end;
writeln(‘DAY DA SAP XEP TANG DAN LA:’);
for i:=1 to n do
write(A[i],’ ‘);
readln
end.
uses crt;
var i,n,j,t:integer;
a:array[0..100] of integer;
BEGIN
clrscr;
write(‘Nhap n:’); readln(n);
for i:=1 to n do
begin
write(‘Nhap a[‘,i,’]’);
readln(a[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[j]<=a[i] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
write(‘Mang sau khi da sap xep:’);
for i:=1 to n do write(a[i],’ ‘);
readln
END.