Untitled
111unknown
plain_text
3 years ago
1.4 kB
12
Indexable
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
Matrix = array of array of Extended;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure InputMatrix(M: Matrix; rows, cols: Integer; SG:TStringGrid);
var i,j:integer;
begin
SetLength(M,rows,cols);
for i:=0 to rows-1 do begin
for j:=0 to cols-1 do
begin
M[i,j]:=strtofloat(SG.Cells[j,i]);
end;
end;
end;
function Average(M: Matrix; rows, cols: Integer): Real;
var i,j:integer;
ans:Real;
begin
ans:=0;
for i:=0 to rows-1 do begin
for j:=0 to cols-1 do
begin
ans:=ans+M[i,j];
end;
end;
Result:=ans/(rows*cols);
end;
procedure TForm1.Button1Click(Sender: TObject);
var X:Matrix;
var Y: Matrix;
begin
InputMatrix(X,3,4,StringGrid1);
InputMatrix(Y,4,2,StringGrid2);
edit1.Text:=floattostr(Average(X, 3, 4));
edit2.Text:=floattostr(Average(Y, 4, 2));
end;
end.Editor is loading...