Bài làm việc với dãy số
In ra màn hình số lớn nhất trong mảng 4
Nhập vào một mảng A in ra màn hình theo thứ tự tăng dần và giảm dần
Bài làm việc với dãy số
In ra màn hình số lớn nhất trong mảng 4
Nhập vào một mảng A in ra màn hình theo thứ tự tăng dần và giảm dần
program oken;
uses crt;
var a: array [1..100] of integer;
i,n,max,j,tam: integer;
begin
clrscr;
write(‘Nhap so phan tu cua mang: ‘); readln(n);
for i:=1 to n do
begin
write(‘a[‘,i,’]: ‘);
readln(a[i]);
end;
max:=a[1];
for i:=2 to n do
if a[i]>max then
max:=a[i];
writeln(‘So lon nhat: ‘,max);
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(‘Mang sau khi sap xep theo giam dan: ‘);
for i:=1 to n do
write(a[i],’ ‘);
writeln;
write(‘Mang sau khi sap xep theo tang dan: ‘);
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;
for i:=1 to n do
write(a[i],’ ‘);
readln;
end.
program ct;
ues crt;
var A:array [1..1000] of integer;
i,j,l,n,tg,max: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;
max:=A[1];
for i:=1 to n do
if A[i]>max then max:=A[i];
writeln(‘So lon nhat trong mang la: ‘,max);
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);
for i:=1 to n-1 do
for l:=i+1 to n do
if A[i]<A[l] then
begin
tg:=A[i];
A[i]:=A[l];
A[l]:=tg;
end;
writeln(‘Mang sap xep theo thu tu giam dan la: ‘);
for i:=1 to n do
write(A[i]:3);
readln;
end.
Học tốt!