begin
if s >= 100 then write(n)
else
begin
k := k + 1;
p := 2*p + k;
uncle1(k, p, s + p, n + 1)
end
end;
begin
write('Sovg’aning yig’indisi ');
uncle1(1, 1, 1, 1);
writeln(' –chi tug’ilgan kunda 100 dollardan oshadi')
end.
Keyingi masalalar shu tarzda yechiladi, shuning uchun ularni o’zingiz mustaqil yeching. Rekursiv proseduralardan foydalaning.
111-misol. Har kuni Bilmasvoy oldingi ikki kunda o’rganilgan chet tillaridagi so’zlari yig’indisining yarmini va yana ikkita so’zni o’rganadi. Bilarvoyning fikricha, Bilmasvoyning kuchi kuniga 50 ta so’z o’rganish kerak bo’lganida butunlay yetmay qoladi. Bilmasvoy birinchi ikki kunda bittadan so’z o’rgangan bo’lsa, uning kuchi necha kundan keyin butunlay tugab qolishini hisoblovchi dastur yozing.
Program L111; { ignoramus – nodon, bilimsiz}
uses Crt;
Procedure expert(n1, n2, n : integer); {expert - bilimdon}
var
a : integer;
begin
if n2 = 50 then write(n)
else
begin
a := n1;
n1 := n2;
n2 := (a + n2) div 2 + 2;
expert(n1, n2, n + 1)
end
end;
begin
write('Bilmasvoyning kuchi');
expert(1, 1, 1);
writeln(' kundan keyin tugaydi')
end.
112-misol. Kumush navbatdagi kitobni talqin etayotgan paytda, o’qilgan betlar nomerlarining yig’indisini hisoblab ko’rdi. Bu yig’indini Q orqali belgilaymiz. Oxirgi o’qilgan betning nomerini aniqlovchi dastur yozing.
Program L112;
uses Crt;
var
q : integer;
Procedure page(n, q, s : integer);
begin
if s >= q then writeln(n - 1)
else page(n + 1, q, s + n)
end;
{----------------------------------------------------------------------------------------}
begin
write('O’qilgan betlar nomerlarining yig’indisini kiriting '); readln(q);
write('Kumush o’qigan oxirgi betning nomeri');
page(1, q, 0)
Do'stlaringiz bilan baham: |