1- misol.[20, 83], [178, 391], [211, 746] oraliqlardagi barcha butun sonlar yig'indisini topish dasturini tuzing.
Yechish. Berilgan uchta oraliqdagi butun sonlarning yig'indisini hisoblash uchun parametrli takrorlash operatoridan uch marta foydalanishga to'g'ri keladi. Masalani berilgan oraliqning boshlang'ich va oxirgi qiymatlarini parametr sifatida olib, shu oraliqdagi butun sonlarning yig'indisini hisoblovchi funksiyadan foydalanib ham yechish mumkin.
Program Summa;
Var i, s, si, s2, s3 : Integer;
Function Sum(nl, n2:Integer):Integer;
Begin
s:=0; For i:=nl To n2 Do s:=s+i; Sum:=s;
End;
BEGIN
Sl:= Sum(20,83); s2 := Sum(178,391); s3:=Sum(211,746);
2-misol. Uchburchakning berilgan tomonlari bo'yicha, uning baland- liklarini aniqlovchi dastur tuzing.
Program Uchburchak_balandligi; Var a, b, c, ha, hb, he: real;
Function H_UB(a, b, c: real): real; { a, b, c — Uchburchak tomonlari } Var yp, s: real;
Begin
yp:= (a+b+c)/2; {Perimetr yarmini hisoblash } s:= Sqrt(yp*(yp~a)*(yp~b)*(yp~c)); {Yuza hisoblash} H_UB:= 2*s/a; {Funksiyaga qiymat berildi }
End; Begin
Write('Uchburchak tomonlari (a,b,c) kiritilsin'); Readln(a,b,c); ha:= H_UB(a, b, c); hb:= H_UB(b, a, c); hc:= H_UB(c, b, a);
Writeln('Uchburchak balandliklari: ');
Writeln('ha= ha:10:4, 'hb= hb:10:4, 'hc= hc:10:4);
Readln
End.
Yangi mavzuni mustaxkamlash.
3-misol. Uchta uchburchak uchlarining quyidagi koordinatalari berilgan: 1) (120,20), (80,170), (140,150); 2) (200,97), (500,156), (210,180); 3) (300,190), (200,390), (415,222).
Shu uchburchaklarni mos ravishda qizil, sariq va yashil ranglarda chizish dasturini tuzing.
Uses Graph;
var gd, gm: Integer; Procedure Uchburchak(xl,yl,x2,y2,x3,y3,col:Integer); begin
SetColor(col); Line(xl,yl,x2,y2); Line(x2,y2,x3,y3);
Line(x3,y3,xl,yl);
end;
Begin gd:=0; InitGraph(gd,gm, "); Uchburchak(120,20,80,170,140,150,4); Uchburchak(200,97,500,156,210,180,14); Uchburchak(300,190,200,390,415,222,2); ReadLn; CloseGraph; End.
Yuqorida keltirilgan dasturlarga e'tiborni qaratib, quyidagi xulosaga kelish mumkin: protsedura va funksiyalarga murojaat etish vaqtida funksiya nomi albatta biror operator tarkibida, protsedura nomi esa alohida (mustaqil) yozilar ekan.
Uyga vazifa: 4- mashqni dasturini tuzish.
Sana :______________
Sinf :_______________
Dostları ilə paylaş: |