Bài 11: Kiểu mảng

Bạn chưa đăng nhập. Vui lòng đăng nhập để hỏi bài
Thùy Linh Hoàng

undefinedbai 3

 

Ngô Tuấn Đạt
12 tháng 5 2021 lúc 9:13

program Mang;
uses crt;
var a:array[1..100] of integer;
x,i,n,j,temp: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 do
for j:=i+1 to n do
        if (a[i] < a[j]) then
                begin
                temp := a[i];
                a[i] := a[j];
                a[j] := temp;
                end;
for i:=1 to n do
        writeln(a[i]);

write('Nhap x = '); readln(x);
a[n+1] := x;

for i:=1 to n+1 do
for j:=i+1 to n+1 do
        if (a[i] < a[j]) then
                begin
                temp := a[i];
                a[i] := a[j];
                a[j] := temp;
                end;

for i:=1 to n+1 do
        writeln(a[i]);
readln;
end.

Nguyễn Lê Phước Thịnh
12 tháng 5 2021 lúc 18:55

Câu 5: 

uses crt;

var s,st:string;

a:array[1..255]of string;

i,d,dem,kt,j,dem1:integer;

begin

clrscr;

write('Nhap xau:'); readln(s);

st:=''

for i:=1 to length(s) do 

  if (s[i] in ['a'..'z']) or (s[i] in ['A'..'Z']) then st:=st+s[i];

d:=length(st);

dem:=1;

a[1]:=st[1];

for i:=1 to d do 

  begin

kt:=0;

for j:=1 to dem do 

  if a[j]=st[i] then kt:=1;

if kt=0 then 

begin

inc(dem);

a[dem]:=st[i];

end;

end;

for i:=1 to dem do 

  begin

dem1:=0;

for j:=1 to d do 

  if a[i]=st[j] then inc(dem1);

writeln(a[i],' xuat hien ',dem1,' lan');

end;

readln;

end.

Nguyễn Lê Phước Thịnh
12 tháng 5 2021 lúc 18:59

Câu 4: 

uses crt;

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

i,n,d:integer;

kt:boolean;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do

  begin

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

end;

d:=abs(a[2]-a[1]);

kt:=true;

for i:=2 to n do 

if abs(a[i]-a[i-1])<>d then 

begin

kt:=false;

break;

end;

if kt=true then writeln('Day la cap so cong')

else writeln('Day khong la cap so cong');

readln;

end.


Các câu hỏi tương tự
Doãn Hoài Trang
Xem chi tiết
Nguyễn Xuân Bắc
Xem chi tiết
HuynhNhu Vo
Xem chi tiết
Duyên
Xem chi tiết
Quỳnh Anh Hồ
Xem chi tiết
Mailan Nguyễn
Xem chi tiết
Ưu Vô
Xem chi tiết
Khánh Linh
Xem chi tiết
Hồng Quân
Xem chi tiết