|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
Вывести матрицу на форму
Помогите пожалуйста!!
Надо найти наименьший элемент матрицы X и записать нули в ту строку и столбец, где он находится. Код HTML:
Последний раз редактировалось Limanskaya, 09.06.2010 в 23:44. |
#2
|
||||
|
||||
А тебе как это необходимо реализовать? Через массивы или через StringGrid или еще как-нибудь?
Всегда пишите код так, будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете. |
#3
|
|||
|
|||
Цитата:
Последний раз редактировалось Limanskaya, 10.06.2010 в 11:43. |
#4
|
||||
|
||||
Код:
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
|
|||
|
|||
записать нули в ту строку и столбец, где находится наим.элемент матрицы
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
|
||||
|
||||
Подправил вроде работает
Код:
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
|
|||
|
|||
AND_REY
Спасибо огромное,все работает А то я уже совсем замучилась с этой задачкой!!! |