IV. Mustahkamlsh Shart bo‘yicha takrorlash operatorlardan qaysilarini bilasiz?
While operatorining ishlashini izohlang.
Repeat operatorining ishlashini izohlang.
Shart bo‘yicha takrorlash operatorlarining parametrli takrorlash operatoridan farqi nimada?
Takrorlash operatorlarini qo‘llash qulay bo‘lgan hollarga mos qilib tushuntirig.
Mashqlar 1. Quyidagi operatorlardagi xatoliklarni aniqlang va izohlang.
a) while 5*6 do SH:=sqr(2); b) WHILE 5>6 do Od:=Od+1;
Javob: shart xato yozilgan. Javob: xato yo`q.
d) Repeat iJavob: shart xato yozilgan. Javob: shart xato yozilgan.
2. Quyidagi operatorlardagi takrorlanishlar sonini aniqlang.
a) x:= – 5; while X>0 do x:=x+2; b) x:= –5; while X<10 do begin x:=x+2; x:=2*x; end;
javob: 0 Javob: cheksiz ko`p
d) i:=0; while i*i <=1.2 do i:=i+0.1; e) k:=5; while k /5 <= 2.5 do k:=k+1.5;
Javob: 11 Javob: 6 marta
4. funksiyaning qiymatlarini [-,] oraliqda 0.3 qadam bilan hisoblash dasturini tuzing.
Program
x,y: real;
begin
x:=pi;
repeat y:=x*sin(x); x:=x+0.3 until x>pi
readln;
end.
5*. N natural son va A1, A2, …, AN butun sonlar ketma-ketligi berilgan. Ularni ketma-ket qo‘shib borib, yig‘indi berilgan N butun sondan ortishi bilan ekranga chiqaruvchi dastur tuzing. Agar barcha sonlar yig‘indisi N dan oshmasa, bu haqida xabar chiqarilsin.
Program
Var s,n,i: integer;
A: array[1..100];
Begin
Write(‘N natural sonni kiriting N=’); readln(n);
For i:=1 to n do
begin Write(i,’-sonni kiriting=); readln(a[i]);end;
while (s<=n) and (i<=n) do begin s:=s+a[i]; i:=i+1; end;
if s>n then writeln(‘S=’,s) else writeln(‘Yig`indi N dan ortmadi’);
readln;
end.
V. Uyga vazifa 3. N natural son berilgan. Kvadrati N dan katta bo‘lmagan barcha natural sonlarni chiqaruvchi dastur tuzing.
Program
Var I, N: integer;
Begin
Write(‘N natural sonni kiririting=’); Readln(n);
I:=1;
While i*i<=N do writeln(i):
Readln;
End.
10>