Delphi döngüler (for,while,repeat) örnek..

nazenin

MiKRoSKoBiKCaNLı
Özel üye
0-50 arasındaki sayıların toplamını,adedini ve çarpımını for,while, ve repeat döngüleriyle ayrı ayrı çöz..

→FOR


var
i,top,adet,çarp:integer;
begin
top:=0 ,adet:=1,çarp:=1;
for i:=0 to 50 do begin
if i mod2=0 then
top:=top+i; // toplar
if i mod 2=0 then
adet:=adet+1; //sayar
if i mod2=0 then
çarp:=çarp*1; //çarpar
end;
write('çiftsayıtoplamı');writeln(top);
write('çiftsayıadedi');writeln(adet);
write('çiftsayıçarpımı');writeln(çarp);
readln;
end.








→WHİLE

var
i,top,adet,çarp:integer;
begin
top:=0 ,adet:=1,çarp:=1;i:=1;
while(i>=0)and(i<=50) do begin
if i mod2=0 then
top:=top+i; // toplar
if i mod 2=0 then
adet:=adet+1; //sayar
if i mod2=0 then
çarp:=çarp*1; //çarpar
i:=i+1;
end;
write('çiftsayıtoplamı');writeln(top);
write('çiftsayıadedi');writeln(adet);
write('çiftsayıçarpımı');writeln(çarp);
readln;
end.







→repeat

var
i,top,adet,çarp:integer;
begin
top:=0 ,adet:=1,çarp:=1;i:=1;
repeat
if i mod2=0 then
top:=top+i; // toplar
if i mod 2=0 then
adet:=adet+1; //sayar
if i mod2=0 then
çarp:=çarp*1; //çarpar
i:=i+1;
until i>50;
readln;
end.
 

nazenin

MiKRoSKoBiKCaNLı
Özel üye
0-100 arası tek ve çift sayı toplamının farkını bulan program..

→ for

var
i,ttop,ctop:integer;
begin
ttop:=0; ctop:=0;
fori:= 0 to 100 do begin
ifi mod2=0 then
ctop:=ctop+i else
ttop:=ttop+i;
end;
write('teksayıtoplamı');writeln(ttop);
write('çiftsayıtoplamı');writeln(ctop);
write('tek-çifttoplamfarkı');writeln(ttop-ctop);
readln;
end.










→while

var
i,ttop,ctop:integer;
begin
ttop:=0; ctop:=0; i:=0;
while i<=100 do begin
ifi mod2=0 then
ctop:=ctop+i else
ttop:=ttop+i;
i:=i+1;
end;
write('teksayıtoplamı');writeln(ttop);
write('çiftsayıtoplamı');writeln(ctop);
write('tek-çifttoplamfarkı');writeln(ttop-ctop);
readln;
end.









→repeat

var
i,ttop,ctop:integer;
begin
ttop:=0; ctop:=0; i:=0;
repeat
ifi mod2=0 then
ctop:=ctop+i else
ttop:=ttop+i;
i:=i+1;
until i>100;
write('teksayıtoplamı');writeln(ttop);
write('çiftsayıtoplamı');writeln(ctop);
write('tek-çifttoplamfarkı');writeln(ttop-ctop);
readln;
end.
 
Top