Program N1(input, output);
Var s: real;
n: integer;
begin
s:=o; n:=1;
while n<=50 do
begin s:=s+1/n;
n:=n+1;
end;
writeln(‘yigindi kiymati s=’,s);
end.
bu yugindini hisoblash dasturida takrorlanish jarayoni n ning kiymati 50ga teng bulguncha davom etadi.
N ning kiymati 50 dan katta bo’lganidan yigindini kymatlarini hisoblash jarayoni tuxtatiladi va natija ekranga chikariladi.
Natija s=4.499...
n=1…500
tamom
S=
S=s+1/n
boshlash
|
Endi ushbu dasturni for operatoridan foydalanib tuzamiz
Program N2(input, output);
Var s: real;
n: integer;
begin
s:=0;
for n:=1 to 50 do
s:=s+1/n;
writeln(‘yigindi kiymati s=’,s);
end.
yigindini kiymati s=4.499…
|
FOR va WHILE operatorlaridan tashkari REPAET operatori yordamida ham takrorlanish jarayonini tashkil etish mumkin. REPAET operatorining umumiy ko’rinishi quyidagicha:
repaet a until b; Bu yerda а-operatorlar tsikl tanasi, b-mantiqiy ifoda.
Agar b shart bajarilsa boshqarish V dan keyingi operatorga utadi, V bajarilmasa tsikl davom etishi tuxtaydi.
Do'stlaringiz bilan baham: |