IV. Mustahkamlash uchun savol va topshiriqlar Dasturda protsedura va funksiyalar qanday maqsadda qo‘llaniladi?
Protsedura va Funksiyalarning farqi nimada?
Parametrli protsedura va funksiyalar haqida so‘zlab bering.
Protseduraning umumiy tuzilishini ifodalab bering.
Funksiyaning umumiy tuzilishini ifodalab bering.
Dasturdagi umumiy va mahalliy o‘zgaruvchilar haqida so‘zlab bering.
Funksiya o’rniga qachon protsedura ishlatish mumkin? Javobingizni izohlang.
Mashqlar
1. Uchta to‘g‘ri to‘rtburchakning har birining bittadan diagonali uchlarining koordinatalari berilgan: 1) 20,20 va 80,200; 2) 200,97 va 500,156; 3) 300,120 va 400,420. Shu to‘g‘ri to‘rtburchaklarni mos ravishda qizil, sariq va yashil raglarda chizish dasturini tuzing.
Uses Graph;
var gd, gm:Integer;
Procedure Turtburchak(x1,y1,x2,y2,rang:Integer);
begin
SetColor(rang); rectangle(x1,y1,x2,y2);
end;
Begin
gd:=0; InitGraph(gd,gm, ‘‘);
Turtburchak(20,20,80,200,4); Turtburchak(200,97,500,156,14);
Turtburchak(300,400,420,420,2);
ReadLn; CloseGraph;
End.
2. Berilgan n natural son uchun S=1·5+2·6+3·7+…+n·(n+4) yig’indini hisoblash dasturini protsedura yordamida tuzing.
Uses crt;
I,s,n,s1: integer;
Procedure summa(k: integer);
Begin S1:=k*(k+4); End;
Begin
Write(‘N ning qiymatini kiriritng: ’); Readln(n);
For i:=1 to n begin Summa(i); S:=s+s1; end;
Writeln(‘S=’,s);
Readln;
End.
V. Uyga vazifa Uchta sondan kattasini topish dasturini tuzing. Buning uchun ikkita sondan kattasini topish funksiyasini tuzing va undan foydalaning.
Qabul qildi : MMIDO` _________S.Egamov Sana:__________________