Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > [ "Начинающим" ]
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 09.06.2010, 22:41
Limanskaya Limanskaya вне форума
Прохожий
 
Регистрация: 09.06.2010
Сообщения: 4
Репутация: 10
По умолчанию Вывести матрицу на форму

Помогите пожалуйста!!
Надо найти наименьший элемент матрицы X и записать нули в ту строку и столбец, где он находится.

Код HTML:
5.02 4.7 -7 -19 -32 82 0.3 57 -100 8.6 17 9 4 -10 33 -5 66 9 18 -7 5 13 -14 17 -8 15 14 5 1 -2 0.5 16 70 17 16
Вывести матрицу на форму для просмотра результата.

Последний раз редактировалось Limanskaya, 09.06.2010 в 23:44.
Ответить с цитированием
  #2  
Старый 10.06.2010, 10:30
Аватар для Kailon
Kailon Kailon вне форума
Активный
 
Регистрация: 06.06.2010
Сообщения: 339
Версия Delphi: 10.4
Репутация: 429
По умолчанию

А тебе как это необходимо реализовать? Через массивы или через StringGrid или еще как-нибудь?
__________________
Всегда пишите код так, будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете.
Ответить с цитированием
  #3  
Старый 10.06.2010, 11:38
Limanskaya Limanskaya вне форума
Прохожий
 
Регистрация: 09.06.2010
Сообщения: 4
Репутация: 10
По умолчанию

Цитата:
Сообщение от Kailon
А тебе как это необходимо реализовать? Через массивы или через StringGrid или еще как-нибудь?
Через StringGrid,на форме надо расположить 2 StringGrida:1 - исходная матрица,во 2 надо вывести получившуюся матрицу(с нулями в той строке и столбце,где находится наименьший элемент матрицы).

Последний раз редактировалось Limanskaya, 10.06.2010 в 11:43.
Ответить с цитированием
  #4  
Старый 10.06.2010, 23:29
Аватар для SerginhoLD
SerginhoLD SerginhoLD вне форума
Новичок
 
Регистрация: 19.11.2009
Сообщения: 73
Репутация: 12
По умолчанию

Код:
procedure TForm1.BitBtn2Click(Sender: TObject);
var
  i,j,k,n:integer;
  c:double;
begin
  c:=strtofloat(stringgrid1.Cells[0,0]); k:=0; n:=0;
  for i:=0 to  stringgrid1.ColCount-1 do
    for j:=0 to  stringgrid1.rowCount-1 do
      if c>strtofloat(stringgrid1.Cells[i,j]) then
      begin
        c:=strtofloat(stringgrid1.Cells[i,j]);
        k:=i; n:=j;
      end;
  for i:=0 to  stringgrid2.ColCount-1 do
    for j:=0 to  stringgrid2.rowCount-1 do
      if (i=k) or (j=n) then stringgrid2.Cells[i,j]:='0'
      else
      stringgrid2.Cells[i,j]:=stringgrid1.Cells[i,j];
end;
__________________
знаете почему внизу эскалатора бабка в будке сидит?
она там педальки крутит и лесенка едет!
Ответить с цитированием
  #5  
Старый 13.06.2010, 21:38
Limanskaya Limanskaya вне форума
Прохожий
 
Регистрация: 09.06.2010
Сообщения: 4
Репутация: 10
По умолчанию записать нули в ту строку и столбец, где находится наим.элемент матрицы

SerginhoLD что-то твоя программа работает!!
Вот написала программу,но работает не совсем правильно
Подскажите,что неправильно....
Работу нужно сдать завтра. Заранее спасибо
Код:
procedure TForm1.FormCreate(Sender: TObject);
begin
stringGrid1.Cells[1,1]:='5,02';
stringGrid1.Cells[1,2]:='57';
stringGrid1.Cells[1,3]:='33';
stringGrid1.Cells[1,4]:='13';
stringGrid1.Cells[1,5]:='1';
stringGrid1.Cells[2,1]:='4,7';
stringGrid1.Cells[2,2]:='-100';
stringGrid1.Cells[2,3]:='-5';
stringGrid1.Cells[2,4]:='-14';
stringGrid1.Cells[2,5]:='-2';
stringGrid1.Cells[3,1]:='-7';
stringGrid1.Cells[3,2]:='86';
stringGrid1.Cells[3,3]:='66';
stringGrid1.Cells[3,4]:='17';
stringGrid1.Cells[3,5]:='0,5';
stringGrid1.Cells[4,1]:='-19';
stringGrid1.Cells[4,2]:='17';
stringGrid1.Cells[4,3]:='9';
stringGrid1.Cells[4,4]:='-8';
stringGrid1.Cells[4,5]:='16';
stringGrid1.Cells[5,1]:='-32';
stringGrid1.Cells[5,2]:='9';
stringGrid1.Cells[5,3]:='18';
stringGrid1.Cells[5,4]:='15';
stringGrid1.Cells[5,5]:='70';
stringGrid1.Cells[6,1]:='82';
stringGrid1.Cells[6,2]:='4';
stringGrid1.Cells[6,3]:='-7';
stringGrid1.Cells[6,4]:='14';
stringGrid1.Cells[6,5]:='17';
stringGrid1.Cells[7,1]:='0,3';
stringGrid1.Cells[7,2]:='-10';
stringGrid1.Cells[7,3]:='5';
stringGrid1.Cells[7,4]:='5';
stringGrid1.Cells[7,5]:='16';
stringGrid2.Cells[1,1]:='5,02';
stringGrid2.Cells[1,2]:='57';
stringGrid2.Cells[1,3]:='33';
stringGrid2.Cells[1,4]:='13';
stringGrid2.Cells[1,5]:='1';
stringGrid2.Cells[2,1]:='4,7';
stringGrid2.Cells[2,2]:='-100';
stringGrid2.Cells[2,3]:='-5';
stringGrid2.Cells[2,4]:='-14';
stringGrid2.Cells[2,5]:='-2';
stringGrid2.Cells[3,1]:='-7';
stringGrid2.Cells[3,2]:='86';
stringGrid2.Cells[3,3]:='66';
stringGrid2.Cells[3,4]:='17';
stringGrid2.Cells[3,5]:='0,5';
stringGrid2.Cells[4,1]:='-19';
stringGrid2.Cells[4,2]:='17';
stringGrid2.Cells[4,3]:='9';
stringGrid2.Cells[4,4]:='-8';
stringGrid2.Cells[4,5]:='16';
stringGrid2.Cells[5,1]:='-32';
stringGrid2.Cells[5,2]:='9';
stringGrid2.Cells[5,3]:='18';
stringGrid2.Cells[5,4]:='15';
stringGrid2.Cells[5,5]:='70';
stringGrid2.Cells[6,1]:='82';
stringGrid2.Cells[6,2]:='4';
stringGrid2.Cells[6,3]:='-7';
stringGrid2.Cells[6,4]:='14';
stringGrid2.Cells[6,5]:='17';
stringGrid2.Cells[7,1]:='0,3';
stringGrid2.Cells[7,2]:='-10';
stringGrid2.Cells[7,3]:='5';
stringGrid2.Cells[7,4]:='5';
stringGrid2.Cells[7,5]:='16';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
A:array[1..5,1..7]of real;
i,j:integer;
k,l:integer;
min:real;
begin
Min:=A[1,1];
for i:=1 to 5 do
for j:=1 to 7 do begin
If A[i,j]< Min then begin
Min:=A[i,j];
l:=j;
k:=i;
end;
end;
for i:=1 to 7 do begin
A[k,i]:=0;
StringGrid2.Cells[k,i]:='0';
end;
for j:=1 to 5 do begin
A[j,l]:=0;
StringGrid2.Cells[j,k]:='0';
end;
end;
end.
Ответить с цитированием
  #6  
Старый 13.06.2010, 23:14
Аватар для AND_REY
AND_REY AND_REY вне форума
Активный
 
Регистрация: 31.03.2009
Адрес: Украина, г.Днепропетровск
Сообщения: 324
Версия Delphi: Delphi7
Репутация: 3877
По умолчанию

Подправил вроде работает

Код:
procedure TForm1.FormCreate(Sender: TObject);
begin
stringGrid1.Cells[1,1]:='5,02';
stringGrid1.Cells[1,2]:='57';
stringGrid1.Cells[1,3]:='33';
stringGrid1.Cells[1,4]:='13';
stringGrid1.Cells[1,5]:='1';
stringGrid1.Cells[2,1]:='4,7';
stringGrid1.Cells[2,2]:='-100';
stringGrid1.Cells[2,3]:='-5';
stringGrid1.Cells[2,4]:='-14';
stringGrid1.Cells[2,5]:='-2';
stringGrid1.Cells[3,1]:='-7';
stringGrid1.Cells[3,2]:='86';
stringGrid1.Cells[3,3]:='66';
stringGrid1.Cells[3,4]:='17';
stringGrid1.Cells[3,5]:='0,5';
stringGrid1.Cells[4,1]:='-19';
stringGrid1.Cells[4,2]:='17';
stringGrid1.Cells[4,3]:='9';
stringGrid1.Cells[4,4]:='-8';
stringGrid1.Cells[4,5]:='16';
stringGrid1.Cells[5,1]:='-32';
stringGrid1.Cells[5,2]:='9';
stringGrid1.Cells[5,3]:='18';
stringGrid1.Cells[5,4]:='15';
stringGrid1.Cells[5,5]:='70';
stringGrid1.Cells[6,1]:='82';
stringGrid1.Cells[6,2]:='4';
stringGrid1.Cells[6,3]:='-7';
stringGrid1.Cells[6,4]:='14';
stringGrid1.Cells[6,5]:='17';
stringGrid1.Cells[7,1]:='0,3';
stringGrid1.Cells[7,2]:='-10';
stringGrid1.Cells[7,3]:='5';
stringGrid1.Cells[7,4]:='5';
stringGrid1.Cells[7,5]:='16';
stringGrid2.Cells[1,1]:='5,02';
stringGrid2.Cells[1,2]:='57';
stringGrid2.Cells[1,3]:='33';
stringGrid2.Cells[1,4]:='13';
stringGrid2.Cells[1,5]:='1';
stringGrid2.Cells[2,1]:='4.7';
stringGrid2.Cells[2,2]:='-100';
stringGrid2.Cells[2,3]:='-5';
stringGrid2.Cells[2,4]:='-14';
stringGrid2.Cells[2,5]:='-2';
stringGrid2.Cells[3,1]:='-7';
stringGrid2.Cells[3,2]:='86';
stringGrid2.Cells[3,3]:='66';
stringGrid2.Cells[3,4]:='17';
stringGrid2.Cells[3,5]:='0,5';
stringGrid2.Cells[4,1]:='-19';
stringGrid2.Cells[4,2]:='17';
stringGrid2.Cells[4,3]:='9';
stringGrid2.Cells[4,4]:='-8';
stringGrid2.Cells[4,5]:='16';
stringGrid2.Cells[5,1]:='-32';
stringGrid2.Cells[5,2]:='9';
stringGrid2.Cells[5,3]:='18';
stringGrid2.Cells[5,4]:='15';
stringGrid2.Cells[5,5]:='70';
stringGrid2.Cells[6,1]:='82';
stringGrid2.Cells[6,2]:='4';
stringGrid2.Cells[6,3]:='-7';
stringGrid2.Cells[6,4]:='14';
stringGrid2.Cells[6,5]:='17';
stringGrid2.Cells[7,1]:='0,3';
stringGrid2.Cells[7,2]:='-10';
stringGrid2.Cells[7,3]:='5';
stringGrid2.Cells[7,4]:='5';
stringGrid2.Cells[7,5]:='16';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
A:array[1..5,1..7]of real;
i,j:integer;
k,l:integer;
min:real;
S: String;
begin
for i:=1 to 3 do
for j:=1 to 5 do
begin
S:= StringGrid1.Cells[i,j];
A[i,j]:= StrToFloat(S);
end;
Min:=A[1,1];
for i:=1 to 5 do
for j:=1 to 7 do begin
If A[i,j]< Min then begin
Min:=A[i,j];
l:=j;
k:=i;
end;
end;
for i:=1 to 7 do begin
A[k,i]:=0;
StringGrid2.Cells[i,k]:='0';
end;
for j:=1 to 5 do begin
A[j,l]:=0;
StringGrid2.Cells[k,j]:='0';
end;
end;
Ответить с цитированием
  #7  
Старый 13.06.2010, 23:29
Limanskaya Limanskaya вне форума
Прохожий
 
Регистрация: 09.06.2010
Сообщения: 4
Репутация: 10
По умолчанию

AND_REY
Спасибо огромное,все работает А то я уже совсем замучилась с этой задачкой!!!
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 19:41.


 

Сайт

Форум

FAQ

RSS лента

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2023

ВКонтакте   Facebook   Twitter