Bài 9. Làm việc với dãy số

Phan Huy

Nhập dãy gồm 10 số

- tìm GTLN, GTNN

tìm các số chia hết cho 3 ở vị trí lẻ

Sắp xếp theo thứ tự tăng dần

híp
1 tháng 5 2019 lúc 20:59

var a:array[1..10] of integer;

i,max,min,j,t:integer;

begin

for i:=1 to 10 do

begin

write('a[',i,']='); readln(a[i]);

end;

max:=a[1] ; min:=a[1];

for i:=2 to 10 do

begin

if max<a[i] then max:=a[i];

if min>a[i] then min:=a[i];

end;

writeln('gtln la:',max);

writeln('gtnn la:',min);

writeln('cac so chia het cho 3 o vi tri le la:');

for i:=1 to 10 do

if (a[i] mod 2=1) and (a[i] mod 3=0) then writeln(a[i],' ');

for i:=1 to 9 do

for j:=i+1 to 10 do

if a[i] > a[j] then

begin

t:=a[i]; a[i]:=a[j]; a[j]:=t;

end;

write('day so sau khi sap xep:');

for i:=1 to 10 do write(a[i]:5);

readln

end.

Bình luận (0)
Nguyễn Trung Hiếu
1 tháng 5 2019 lúc 20:40

uses crt;
var j,tg,s,max,min,i,n:longint;
a:array[1..100000] of longint;
begin
clrscr;
write('Nhap 10 so:'); writeln;
for i:=1 to 10 do
begin
write('a[',i,']=');readln(a[i]);
end;
min:=a[1];max:=a[1];
for i:=2 to 10 do
begin
if a[i]>max then max:=a[i];
if a[i]<min then min:=a[i];
end;
write('GTLN la: ',max); write(' ');
writeln('GTNN la :',min);
for i:=1 to 10 do
if (a[i] mod 3=0) and (i mod 2<>0) then 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;
for i:=1 to 10 do
write(a[i],' ');
readln
end.

Bình luận (0)

Các câu hỏi tương tự
Học .com
Xem chi tiết
Hùngg Nguyễnn
Xem chi tiết
Nguyễn Thị Hồng Cảnh
Xem chi tiết
Asuna
Xem chi tiết
Trung Kien
Xem chi tiết
Epic Kevin
Xem chi tiết
Diễn Mai
Xem chi tiết
nhannhan
Xem chi tiết
nhannhan
Xem chi tiết