Đề bài : Viết chương trình nhập vào mảng a hoặc b,c tùy ý a, In ra màn hình mảng vừa nhập b, Sắp xếp mảng theo thứ tự tăng dần hoặc giảm dần c, Điểm xem trong mảng có bao nhiêu phần tử Mn giúp mk vs ạ
2 câu trả lời
program ct;
uses crt;
var i,n,d,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;
{--------cau a--------}
writeln('cac phan tu vua nhap la');
for i:=1 to n do
write(A[i],' ');
{--------cau b--------}
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;
write('day so sap xep theo thu tu tang dan la');
for i:=1 to n do
write(A[i],' ');
{-----------cau c----------}
d:=0;
for i:=1 to n do d:=d+1;
writeln('co',d,' phan tu trong mang');
readln
end.
program ct;
uses crt;
var A:array[1..1000] of integer;
i,j,n,k:integer;
begin clrscr;
write('Nhap so phan tu: '); readln(n);
for i:=1 to n do
begin
write('nhap mang A[',i,']:=');readln(A[i]);
end;
write('Mang vua nhap la: ');
for i:=1 to n do
write(A[i]:3);
for i:=1 to n-1 do
for j:=i+1 to n do
if A[i]>A[j] then
begin
k:=A[i];
A[i]:=A[j];
A[j]:=k;
end;
write('Mang sap xep theo thu tu tang dan la: ');
for i:=1 to n do
write(A[i]:3);
for i:=1 to n-1 do
for j:=i+1 to n do
if A[i]<A[j] then
begin
k:=A[i];
A[i]:=A[j];
A[j]:=k;
end;
write('Mang sap xep theo thu tu giam dan la: ');
for i:=1 to n do
write(A[i]:3);
write('Mang co ',n,' phan tu');
readln;
end.
Học tốt!