"Из матрицы А(mxn) надо исключить строки, содержащие хотябы один нулевой элемент"
Const
n = ...;
m = ...;
Type ma3x = array[1 .. n, 1 .. m] of integer;
var
mx: ma3x;
i, j: integer; no_null: boolean;
begin
{ тут заполняем матрицу }
for i := 1 to n do
begin
no_null := true;
for j := 1 to m do
no_null := no_null and (arr[i, j] <> 0);
if no_null then
begin
for j := 1 to m do write(arr[i, j]:4);
writeln
end;
end;
end.
var
i,j,n:integer;
no_null:boolean;
mas:array[0..100,0..100] of integer;
begin
if (edit1.Text='') then
showmessage('Çàïîëíèòå ïîëÿ')
else
begin
randomize;
n:=strtoint(edit1.text);
stringgrid1.ColCount:=n;
stringgrid1.RowCount:=n;
for i:=0 to n do
for j:=0 to n do
begin
mas[i,j]:= random(20)-10;
stringgrid1.Cells[i,j] := inttostr (mas[i,j]);
end;
For i:=0 to n do
for j:=0 to n do
begin
no_null:=true;
no_null:=no_null and (mas[i,j]<>0);
If no_null then
begin
for j:=0 to n do { <-- Вот в этой строке}
stringgrid2.Cells[i,j] := inttostr (mas[i,j]);
end;
М | Lesnik, для отметки места в программе используй комментарии. Лопарь |
1. Сделать нормальное форматирование.
2. Прочитать, что за ошибка.
For i:=0 to n do
for j:=0 to n do
begin
no_null:=true;
no_null:=no_null and (mas[i,j]<>0);
If no_null then
begin
for j:=0 to n do { <-- Вот в этой строке}
stringgrid2.Cells[i,j] := inttostr (mas[i,j]);
end;
Программа в delphi работает неправильно.
С этой переменой h она удаляет не строчки а столбцы. И учитываю, что у меня результат выводится в Grid, пустые столбцы остаются
Как можно решить эту проблему?
procedure TForm1.Button1Click(Sender: TObject);(ты должен позаботиться о том, что у StringGrid-ов нет FixedCols/FixedRows)
var
i, j, curr: integer;
no_null: boolean;
begin
curr := 0;
For i:=0 to pred(StringGrid1.RowCount) do begin
no_null:=true;
for j:=0 to pred(StringGrid1.ColCount) do
no_null:=no_null and (strtoint(StringGrid1.Cells[j,i]) <> 0);
If no_null then begin
for j:=0 to pred(StringGrid1.ColCount) do
stringgrid2.Cells[j, curr] := StringGrid1.Cells[j,i];
inc(curr);
end;
end;
StringGrid2.RowCount := curr;
end;
procedure TForm1.Button1Click(Sender: TObject);(ты должен позаботиться о том, что у StringGrid-ов нет FixedCols/FixedRows)
var
i, j, curr: integer;
no_null: boolean;
begin
curr := 0;
For i:=0 to pred(StringGrid1.RowCount) do begin
no_null:=true;
for j:=0 to pred(StringGrid1.ColCount) do
no_null:=no_null and (strtoint(StringGrid1.Cells[j,i]) <> 0);
If no_null then begin
for j:=0 to pred(StringGrid1.ColCount) do
stringgrid2.Cells[j, curr] := StringGrid1.Cells[j,i];
inc(curr);
end;
end;
StringGrid2.RowCount := curr;
end;
В твоем проекте вот этот код:
procedure TForm1.Button1Click(Sender: TObject);
var
i, j, curr: integer;
no_null: boolean;
n: integer;
begin
n:=strtoint(edit1.text); // Было добавлено для отсечения всех незаполненных ячеек
stringgrid1.ColCount:=n;
stringgrid1.RowCount:=n;
curr := 0;
For i:=0 to pred(StringGrid1.RowCount) do begin
no_null:=true;
for j:=0 to pred(StringGrid1.ColCount) do
no_null:=no_null and (strtoint(StringGrid1.Cells[j,i]) <> 0);
If no_null then begin
for j:=0 to pred(StringGrid1.ColCount) do
stringgrid2.Cells[j, curr] := StringGrid1.Cells[j,i];
inc(curr);
end;
end;
StringGrid2.RowCount := curr;
end;