For sikli yordamida amalga oshirish mumkin. Elementni massiv boshiga (birinchi o’ringa) ko’chirish uchun prosedura


Procedure search_number(d : integer; a : t; var


Download 36.98 Kb.
bet3/16
Sana01.04.2023
Hajmi36.98 Kb.
#1318578
1   2   3   4   5   6   7   8   9   ...   16
Bog'liq
masala 1

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 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 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’);

Download 36.98 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   16




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling