|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
Проверить программу
Здравствуйте! Прошу проверишь программу. Почему то не хочет считать . Пишет что min и max равны 0. Сообщений компилятора никаких нет.
Задача: Дана действительная матрица размера N х M элементов, все элементы которой различны. Найти наибольший и наименьший элементы матрицы. Как делал: Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; StringGrid1: TStringGrid; Button1: TButton; Button2: TButton; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; procedure Edit1Change(Sender: TObject); procedure Edit2Change(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; n,m,j,i,k,min,max:integer; r:array[1..20,1..20] of integer; implementation {$R *.dfm} procedure TForm1.Edit1Change(Sender: TObject);//Ввод количества строк массива var i:integer; begin n:=strtoint(edit1.Text); stringgrid1.RowCount:=n+1; for i:=1 to n do stringgrid1.Cells[0,i]:=inttostr(i); end; procedure TForm1.Edit2Change(Sender: TObject);//Ввод количества столбцов массива и вывода номера столбца в Stringgrid1.Cells[i,0] var j:integer; begin m:=strtoint(edit2.Text); stringgrid1.ColCount:=m+1; for j:=1 to m do stringgrid1.Cells[j,0]:=inttostr(j); end; procedure TForm1.Button1Click(Sender: TObject); var j,i,min,max:integer; begin min:=r[1,1]; For i:=1 to StringGrid1.RowCount-1 do For j:=1 to Form1.StringGrid1.ColCount-1 do if r[i,j]<min then begin min:=r[i,j]; end; max:=r[1,1]; For i:=1 to StringGrid1.RowCount-1 do For j:=1 to Form1.StringGrid1.ColCount-1 do if r[i,j]>max then begin max:=r[i,j]; end; Label4.Caption:=IntToStr(min); Label3.Caption:=IntToStr(max); end; procedure TForm1.Button2Click(Sender: TObject); begin close; end; end. |
#2
|
||||
|
||||
Ну это же очевидно! Данные ты пытаешься читать из массива r, а они у тебя в стринггриде, и в массив не переносятся...
Оставайтесь хорошими людьми... VK id2634397, ds [at] phoenix [dot] dj |
#3
|
|||
|
|||
DJ PhoeniX, спасибо!
Спасибо! Подправил: Уже считает но всё равно не корректно...
Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; StringGrid1: TStringGrid; Button1: TButton; Button2: TButton; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; procedure Edit1Change(Sender: TObject); procedure Edit2Change(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; n,m,j,i,k,min,max:integer; r:array[1..20,1..20] of integer; implementation {$R *.dfm} procedure TForm1.Edit1Change(Sender: TObject);//Ввод количества строк массива var i:integer; begin n:=strtoint(edit1.Text); stringgrid1.RowCount:=n+1; for i:=1 to n do stringgrid1.Cells[0,i]:=inttostr(i); end; procedure TForm1.Edit2Change(Sender: TObject);//Ввод количества столбцов массива и вывода номера столбца в Stringgrid1.Cells[i,0] var j:integer; begin m:=strtoint(edit2.Text); stringgrid1.ColCount:=m+1; for j:=1 to m do stringgrid1.Cells[j,0]:=inttostr(j); For i:=1 to StringGrid1.ColCount-1 do For j:=1 to StringGrid1.RowCount-1 do begin StringGrid1.Cells[j,i]:=ШтеToStr(r[i,j]); end; end; procedure TForm1.Button1Click(Sender: TObject); var j,i,min,max:integer; begin min:=r[1,1]; For i:=1 to StringGrid1.RowCount-1 do For j:=1 to Form1.StringGrid1.ColCount-1 do begin r[i,j]:=StrToInt(StringGrid1.Cells[j,i]); end; if r[i,j]<min then begin min:=r[i,j]; end; max:=r[1,1]; For i:=1 to StringGrid1.ColCount-1 do For j:=1 to StringGrid1.RowCount-1 do begin r[i,j]:=StrToInt(StringGrid1.Cells[j,i]); end; if r[i,j]>max then begin max:=r[i,j]; end; Label4.Caption:=IntToStr(min); Label3.Caption:=IntToStr(max); end; procedure TForm1.Button2Click(Sender: TObject); begin close; end; end. |
#4
|
||||
|
||||
О боже... Не множьте сущности, мол.чек.
Код:
procedure TForm1.Button1Click(Sender: TObject); var j,i,min,max:integer; begin min:=StrToInt(StringGrid1.Cells[j,i]); min:=max; For i:=1 to StringGrid1.RowCount-1 do For j:=1 to StringGrid1.ColCount-1 do begin if StrToInt(StringGrid1.Cells[j,i])<min then min:=StrToInt(StringGrid1.Cells[j,i]); if StrToInt(StringGrid1.Cells[j,i])>max then max:=StrToInt(StringGrid1.Cells[j,i]); end; Label4.Caption:=IntToStr(min); Label3.Caption:=IntToStr(max); end; Оставайтесь хорошими людьми... VK id2634397, ds [at] phoenix [dot] dj |