for i := 1 to n 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’);
Do'stlaringiz bilan baham: |