1,Viết chương trình sắp xếp dãy số giảm dần 2,Viết chương trình sắp xếp dãy số tăng dần
2 câu trả lời
1
program ct;
uses crt;
var i,n,j,tam:integer;
A:array[1..100] of integer;
begin
clrscr;
write('nhap n:=');readln(n);
for i:=1 to n do
begin
write('nhap mang A[',i,']:=');readln(A[i]);
end;
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;
writeln('day so theo thu tu giam dan la');
for i:=1 to n do
write(A[i],' ');
readln
end.
2
program ct;
uses crt;
var i,n,j,tam:integer;
A:array[1..100] of integer;
begin
clrscr;
write('nhap n:=');readln(n);
for i:=1 to n do
begin
write('nhap mang A[',i,']:=');readln(A[i]);
end;
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;
writeln('day so theo thu tu tang dan la');
for i:=1 to n do
write(A[i],' ');
readln
end.
1)
program ct;
ues crt;
var A:array [1..1000] of integer;
i,j,n,tg:integer;
begin clrscr;
write('Nhap so phan tu n: '); readln(n);
for i:=1 to n do
begin
writeln('Nhap so thu ',i,': '); readln(A[i]);
end;
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('Mang sap xep theo thu tu giam dan la: ');
for i:=1 to n do
write(A[i]:3);
readln;
end.
2)
program ct;
ues crt;
var A:array [1..1000] of integer;
i,j,n,tg:integer;
begin clrscr;
write('Nhap so phan tu n: '); readln(n);
for i:=1 to n do
begin
writeln('Nhap so thu ',i,': '); readln(A[i]);
end;
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('Mang sap xep theo thu tu tang dan la: ');
for i:=1 to n do
write(A[i]:3);
readln;
end.
Học tốt!