2) viết chương trình nhập dãy n số in ra theo thứ tự
a) tăng dần
b) giảm dần
Quảng cáo
1 câu trả lời 332
1)
program hotrotinhoc ;
var a : array[1..32000] of integer ;
i,n,tong : integer;
begin
write('Nhap do dai cua day n:'); readln(n);
writeln('Nhap gia tri cua cac phan tu ');
for i:= 1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
tong:=0;
for i:=1 to n do
if a[i] mod 2 <> 1 then tong:=tong+a[i];
write('Tong cac so chan la :',tong);
readln
end.
2)
a,
program ct;
uses crt;
var n,i,tam,j: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;
write(‘day so sau khi sap xep la:’);
for i:=1 to n do
write(A[i]:4);
readln
end.
b,
uses crt;
var a:array[1..100]of integer;
i,n,j,tam:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('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;
for i:=1 to n do
write(a[i]:4);
readln;
end.
Quảng cáo
Bạn cần hỏi gì?
Câu hỏi hot cùng chủ đề
-
Hỏi từ APP VIETJACK45513
-
Hỏi từ APP VIETJACK28408
