Çàäà÷à: Çàäàí äâóõìåðíûé ìàññèâ ÷èñåë. Ðàçìåðíîñòü ìàññèâà îïðåäåëÿåò ïîëüçîâàòåëü (ïðè çàïóñêå ïðîãðàììû ðàçìåðíîñòü 10×10). Ýëåìåíòû ìàòðèöû ôîðìèðóþòñÿ ñëó÷àéíûì îáðàçîì. Íàéòè êîëè÷åñòâî ÷åòíûõ ýëåìåíòîâ ìàòðèöû è âûïèñàòü èõ â êîìïîíåíò Memo.
Òåêñò ïðîãðàììû:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ComCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
StringGrid2: TStringGrid;
Label3: TLabel;
StringGrid3: TStringGrid;
Button4: TButton;
Label4: TLabel;
Label5: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Button5: TButton;
StringGrid4: TStringGrid;
Label6: TLabel;
Label7: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Button6: TButton;
Button7: TButton;
Edit5: TEdit;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure ComboBox1Click(Sender: TObject);
procedure ComboBox2Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mas:array[1..10] of integer;
matr:array[1..10,1..10] of integer;
i,j:integer;
k,s,buf,p:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
randomize;
…
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
for i:=1 to 10 do begin
…
StringGrid2.Cells[i-1,0]:=IntToStr(mas[i]);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
s:=0;
…
Edit2.Text:=IntToStr(s);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
for i:=1 to 10 do begin
…
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
k:=0;
…
Edit4.Text:=IntToStr(p);
end;
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
StringGrid4.RowCount:=strtoint(ComboBox1.Items[ComboBox1.ItemIndex]);
end;
procedure TForm1.ComboBox2Click(Sender: TObject);
begin
StringGrid4.ColCount:=strtoint(ComboBox2.Items[ComboBox2.ItemIndex]);
end;
//çàïîëíåíèå ìàòðèöû
procedure TForm1.Button6Click(Sender: TObject);
begin
randomize;
for i:=1 to strtoint(ComboBox1.Items[ComboBox1.ItemIndex]) do begin
for j:=1 to strtoint(ComboBox2.Items[ComboBox2.ItemIndex]) do begin
matr[i,j]:=random(20);
StringGrid4.Cells[j-1,i-1]:=IntToStr(matr[i,j]);
end;
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
k:=0;
Memo1.Clear;
for i:=1 to strtoint(ComboBox1.Items[ComboBox1.ItemIndex]) do begin
for j:=1 to strtoint(ComboBox2.Items[ComboBox2.ItemIndex]) do begin
if matr[i,j] mod 2 =0 then begin
k:=k+1;
Memo1.Text:=Memo1.Text+inttostr(matr[i,j])+' ';
end;
end;
end;
Edit5.Text:=IntToStr(k);
end;
end.
|