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


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

for i := 1 to do write(a[i], ' ');
writeln
end.
193-misol. Dasturni shunday o’zgartiringki, u o’zining qiymati bilan berilgan elementni foydalanuvchi ko’rsatgan joyga o’tkazsin.
Tavsiyalar. Bu masalani tuzishda uchraydigan qiyinchiliklardan bittasi, ko’rsatilgan joy nomeri ko’chirilayotgan element egallagan joy nomeridan katta yoki kichkina bo’lishi mumkin.
Shu bilan bog’liq holda, siz elementni ko’chirish sikli qanday tuzilishi keraklgini o’ylab chiqishingiz kerak.
Program L193;
uses Crt;
const
n = 20;
type
t = array[1..n] of integer;
var
a : t;
i, k, d, m, s, p : 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);
begin
k := 0;
repeat
k := k+1
until a[k] = d
end;
{----------------------------------------------------------------------------------------}
Procedure transpose_number(n, k, m : integer; var a : t);
var
s, p, i : integer;
begin
if m > k then s := 1 else s := -1;
i := k;
repeat
p := a[i+s];
a[i+s] := a[i];
a[i] := p; i := i+s
until i = m - s - 1;
writeln('Elementni ko’chirgandan 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