TForm1 = class(TForm) StringGrid1: TStringGrid; Label1: TLabel; Button1: TButton; Label2: TLabel; procedure Button1Click(Sender: TObject); procedure StringGrid1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var a : array[1..5] of integer; summ: integer; sr: real; i: integer; begin for i:= 1 to 5 do if Length(StringGrid1.Cells[i-1, 0]) <>0 then a[i] := StrToInt(StringGrid1.Cells[i-1,0]) else a[i] := 0; summ := 0; for i :=1 to 5 do summ := summ + a[i]; sr := summ / 5; Label1.Caption := 'Elimentlari yig`indisi: ' + IntToStr(summ) + #13+ 'O‘rta arfimetigi: ' + FloatToStr(sr); end; procedure TForm1.StringGrid1Click(Sender: TObject); var Key: Char; begin case Key of #8,'0'..'9' : ; #13: if StringGrid1.Col < StringGrid1.ColCount-1 then StringGrid1.Col := StringGrid1.Col + 1; else key := Chr(0); end; end; end. Dastur kiritilganidan so‘ng, biron bir nom bilan saqlaymiz.
Dastur ishini yakunlab ma’lum bir qiymatlari yachyekalarga kiritganimizda
Oynani umumiy ko‘rinishi holatini keltiramiz:
6-rasm .
Hosil bo‘lgan ko‘rinishdan foydalanib istalgan 5 o‘lchovli massivlarni elimentlarini yig`indisini va o‘rta arfimetigini hisoblashimiz mumkin. Buning uchun uning qiymatlarini kiritish kifoya.
Misol. massiv elementlarini eng kichchigina va eliment nomerini toppish dasturini tuzing.
Masala yechish oynasi va mos dastur modulini keltiramiz.