![]() |
|
#1
|
|||
|
|||
![]() Заполнить двухмерный массив M*N случайными целыми числами из диапазона [-40,40]. Определить : минимальное значение для элементов, расположенных на главной диагонали, и максимальное значение для элементов, расположенных на побочной диагонали.
|
#2
|
||||
|
||||
![]() Заполни, определи. Что конкретно не получается?
Если ответ "всё" - шагом марш в раздел "Работа". jmp $ ; Happy End! The Cake Is A Lie. |
#3
|
|||
|
|||
![]() Код:
var a:array[1..100,1..100] of integer; m,n: integer; min,max: Integer; i,j: integer; begin randomize; //StringGrid1.visible:=True; n:=strtoint (edit1.text); m:=strtoint (edit2.text); //SetLength(a,n,m); for i:=1 to n do for j:=1 to m do a[i,j]:=-40+random(80); StringGrid1.visible:=True; stringgrid1.RowCount:=n; stringgrid1.ColCount:=m; with StringGrid1 do // позволяет каждый раз не обращаться к имени компонента begin for j:=1 to RowCount do // цикл для вывода номеров строк Cells[0,j]:=InttoStr(j); // в первом столбце for i:=1 to ColCount do // цикл для вывода номеров столбцов Cells[i,0]:=IntToStr(i); // в первой строке for i:=1 to n do // циклы для вывода элементов for j:=1 to m do // массива в таблицу Cells[j,i]:=IntToStr(a[i-1,j-1]); //for i:=1 to n do //for j:=1 to m do //if (i=j)and(a[i,j]<min) then min:=a[i,j]; //if ((m-i+1)=j)and(max<a[m-i+1,j]) then max:=a[m-i+1,j]; label1.Caption:= inttostr (min); //label2.Caption:= inttostr (max); //end; end; end; //end; end. Последний раз редактировалось Admin, 12.06.2012 в 17:15. |
#4
|
|||
|
|||
![]() Помогите, в чем ошибка?
|
#5
|
|||
|
|||
![]() какие симптомы ошибки?
|
#6
|
|||
|
|||
![]() С минимальным элементом проблема, аналогично максимальный. Выводит не правильно.
|
#7
|
||||
|
||||
![]() Меня ещё учили, что на делфи надо начинать счёт с 0.
Код:
for i:=0 to n-1 do Для массива, где n=m главная диагональ будет Код:
if i=j then if StringGrid1.Cells[j,i]<min then min:=SG1.Cells[j,i] |
#8
|
|||
|
|||
![]() Цитата:
|
#9
|
|||
|
|||
![]() Нет, не правильно(
|
#10
|
|||
|
|||
![]() а я говорю правильно
![]() |
#11
|
||||
|
||||
![]() Для массива размерностью m*n (в т.ч. m<>n) вот код:
Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; StringGrid: TStringGrid; Label1: TLabel; Label2: TLabel; Edit2: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; mas:array of array of integer; n,m,i,j:byte; max,min:integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin {Добавить сюда процедуры по очистке Label1 и Label2. Процедуры по очистке ячеек StringGrid } min:=40; max:=-40; m:=StrToInt(Edit1.Text); n:=StrToInt(Edit2.Text); SetLength(mas,m); for i:=0 to m-1 do setLength(mas[i],n); randomize; for i:=0 to m-1 do for j:=0 to n-1 do begin mas[i,j]:=random(81)-40; StringGrid.Cells[j,i]:=IntToStr(mas[i,j]); if i=j then if mas[i,j]<min then min:=mas[i,j]; if j=(n-1)-i then if mas[i,j]>max then max:=mas[i,j]; end; Label1.Caption:=('Minnimum budet'+#13#10+IntToStr(min)); Label2.Caption:=('Maximum budet'+#13#10+IntToStr(max)); // mas:=nil; // не забываем очищать память end; end. Последний раз редактировалось R-18Rus, 12.06.2012 в 22:03. |
#12
|
|||
|
|||
![]() Спасибо большое!
![]() |
#13
|
|||
|
|||
![]() Очень помогли
![]() |
#14
|
|||
|
|||
![]() А вы мне не подсказали бы, как на нее составить блок-схему?? Пожалуйста!
|
#15
|
||||
|
||||
![]() Я сам в блок схемах не силён
|