будте так любезны,напишите глупой(в информатике) студентке программу с матрицами...
условие таково:
:arrow: задана матрица второго порядка.найти её определитель.
буду весьма благодарна

Модераторы: Хыиуду, MOTOCoder, Medved, dr.Jekill
Код: Выделить всё
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids;
const
MtxSize = 5;
type
TMatrix = array[1..MtxSize, 1..MtxSize] of Integer;
TForm1 = class(TForm)
sg: TStringGrid;
BitBtn1: TBitBtn;
Button1: TButton;
Lbl1: TLabel;
Lbl2: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mtx : TMatrix;
ar : Array[1..MtxSize*MtxSize] of Integer;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var x, y: Integer;
begin
for x:=0 to sg.RowCount-1 do
for y:=0 to sg.ColCount-1 do
sg.Cells[y,x] := Inttostr(random(50)-25);
end;
procedure TForm1.Button1Click(Sender: TObject);
var x, y, n : Integer;
nzrc,maxval : Integer;
Sorted : Boolean;
begin
for x:=0 to MtxSize-1 do
for y:=0 to MtxSize-1 do
begin
if not TryStrToInt(sg.Cells[y,x], n) then n := 0;
mtx[y+1,x+1] := n;
ar[x+y*MtxSize] := n;
end;
nzrc := 0;
for x:=1 to MtxSize do
begin
n := 0;
for y:=1 to MtxSize do if mtx[y,x] = 0 then inc(n);
if n = 0 then inc(nzrc);
end;
Lbl1.Caption := 'Non-zero row count : '+Inttostr(nzrc);
Sorted := false;
While not Sorted do
begin
Sorted := true;
For x := 1 to MtxSize*MtxSize-1 do
if ar[x]<ar[x+1] then
begin
n := ar[x];
ar[x] := ar[x+1];
ar[x+1] := n;
Sorted := false;
end;
end;
x := 1;
while (x<>MtxSize*MtxSize) and (ar[x]<>ar[x+1]) do inc(x);
if x = MtxSize*MtxSize
then Lbl2.Caption := 'There is no value that exists more than in one cell'
else Lbl2.Caption := 'Maximum value that exists more than in one cell is '+Inttostr(ar[x]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SG.RowCount := MtxSize;
SG.ColCount := MtxSize;
end;
end.
somewhere писал(а):Код: Выделить всё
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, Grids; const MtxSize = 5; type TMatrix = array[1..MtxSize, 1..MtxSize] of Integer; TForm1 = class(TForm) sg: TStringGrid; BitBtn1: TBitBtn; Button1: TButton; Lbl1: TLabel; Lbl2: TLabel; procedure BitBtn1Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; mtx : TMatrix; ar : Array[1..MtxSize*MtxSize] of Integer; implementation {$R *.dfm} procedure TForm1.BitBtn1Click(Sender: TObject); var x, y: Integer; begin for x:=0 to sg.RowCount-1 do for y:=0 to sg.ColCount-1 do sg.Cells[y,x] := Inttostr(random(50)-25); end; procedure TForm1.Button1Click(Sender: TObject); var x, y, n : Integer; nzrc,maxval : Integer; Sorted : Boolean; begin for x:=0 to MtxSize-1 do for y:=0 to MtxSize-1 do begin if not TryStrToInt(sg.Cells[y,x], n) then n := 0; mtx[y+1,x+1] := n; ar[x+y*MtxSize] := n; end; nzrc := 0; for x:=1 to MtxSize do begin n := 0; for y:=1 to MtxSize do if mtx[y,x] = 0 then inc(n); if n = 0 then inc(nzrc); end; Lbl1.Caption := 'Non-zero row count : '+Inttostr(nzrc); Sorted := false; While not Sorted do begin Sorted := true; For x := 1 to MtxSize*MtxSize-1 do if ar[x]<ar[x+1] then begin n := ar[x]; ar[x] := ar[x+1]; ar[x+1] := n; Sorted := false; end; end; x := 1; while (x<>MtxSize*MtxSize) and (ar[x]<>ar[x+1]) do inc(x); if x = MtxSize*MtxSize then Lbl2.Caption := 'There is no value that exists more than in one cell' else Lbl2.Caption := 'Maximum value that exists more than in one cell is '+Inttostr(ar[x]); end; procedure TForm1.FormCreate(Sender: TObject); begin SG.RowCount := MtxSize; SG.ColCount := MtxSize; end; end.
Все это там уже находится. Тогда убираем описатель типа TMatrix, переменную Mtx и заменяем код в процедуре" писал(а):Ну и надо найти кол-во строк, не содержащих ни одного нулевого элемента и максимальное из чисел, встречающихся в заданной матрице более одного раза. Что надо изменить, чтоб было так?
Код: Выделить всё
procedure TForm1.Button1Click(Sender: TObject);
var x, y, n : Integer;
nzrc,maxval : Integer;
Sorted : Boolean;
begin
for x:=0 to MtxSize-1 do
for y:=0 to MtxSize-1 do
ar[x+y*MtxSize] := StrToInt(sg.Cells[y,x]);
nzrc := 0;
for x:=0 to MtxSize-1 do
begin
n := 0;
for y:=0 to MtxSize-1 do if StrToInt(sg.Cells[y,x]) = 0 then inc(n);
if n = 0 then inc(nzrc);
end;
Lbl1.Caption := 'Non-zero row count : '+Inttostr(nzrc);
Sorted := false;
While not Sorted do
begin
Sorted := true;
For x := 1 to MtxSize*MtxSize-1 do
if ar[x]<ar[x+1] then
begin
n := ar[x];
ar[x] := ar[x+1];
ar[x+1] := n;
Sorted := false;
end;
end;
x := 1;
while (x<>MtxSize*MtxSize) and (ar[x]<>ar[x+1]) do inc(x);
if x = MtxSize*MtxSize
then Lbl2.Caption := 'There is no value that exists more than in one cell'
else Lbl2.Caption := 'Maximum value that exists more than in one cell is '+Inttostr(ar[x]);
end;
Понятно. А как поступать с одномерными массивами? например здесь: В одномерном массиве, состоящем из n целочисленных элементов вычислить: а) номер минимального по модулю элемента массива; b) сумму модулей элементов массива, расположенных после первого отрицательного элемента массива. Преобразовать массив таким образом, чтобы сначала располагались все элементы, попадающие в интервал [a;b], а затем - все остальные. Все вроде просто, на Паскале я могу все это претворить в жизнь, но Delphi не мой конек. Помоги пожалуйста и с одномерным. Потом я надеюсь по этим образцам и сам соорентируюсь.somewhere писал(а):Все это там уже находится. Тогда убираем описатель типа TMatrix, переменную Mtx и заменяем код в процедуре