Procedure search_number(d : integer; a : t; var k : integer);
begin
k := 0;
repeat
k := k + 1
until a[k] = d
end;
Dasturning o’zini esa uchta proseduradan: massivni yaratish - create; element nomerini qidirish - search_number va elementni massiv boshiga ko’chirish- transp_begin tuzish mumkin.
U quyidagi ko’rinishda bo’ladi:
Program L192;
uses Crt;
const
n = 20;
type
t = array[1..n] of integer;
var
a : t;
i, k, d : integer;
{----------------------------------------------------------------------------------------}
Procedure create(n : integer; var a : t);
var
i : integer;
begin
randomize;
writeln('Berilgan butun sonli massiv');
for i := 1 to n do
begin
a[i] := random(201) - 100; write(a[i], ' ')
end;
writeln
end;
{----------------------------------------------------------------------------------------}
Procedure search_number(d : integer; a : t; var k : integer);
var
i : integer;
begin
i := 0;
repeat
i := i + 1
until a[i] = d;
k := i
end;
{----------------------------------------------------------------------------------------}
Procedure transp_begin(n, k : integer; var a : t);
var
i, p : integer;
begin
for i := k downto 2 do
begin
p := a[i-1];
a[i-1] := a[i];
a[i] := p
end
end;
{----------------------------------------------------------------------------------------}
begin
create(n, a);
write('O’tkaziayotgan elementni kiriting'); readln(d);
search_number(d, a, k);
transp_begin(n, k, a);
writeln('Elementni boshiga o’tkazgandan so’ng hosil bo’lgan massiv’);
Do'stlaringiz bilan baham: |