доброго времени суток! само задание звучит так: Указание: работу выполнить в Delphi, использовать элемент формы TStringGrid (панель Additional). Дана таблица целых чисел ai, bi. Заполнить третью и четвертую строки значениями НОД(ai, bi), НОК(ai, bi). ai 1 3 4 8 … bi 2 3 2 6 … НОД(ai, bi) 1 3 2 2 … НОК(ai, bi) 2 3 4 24 …
type TForm1 = class(TForm) StringGrid1: TStringGrid; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure FormPaint(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm} function NOD(A, B: longint): longint; begin while (a <> 0) and (b <> 0) do if a >= b then a := a mod b else b := b mod a; NOD := a + b; end;
function NOK(A, B: longint): longint; begin NOK := a * b div NOD (a, b) end;
procedure TForm1.Button1Click(Sender: TObject); var i, j: Integer; begin with StringGRid1 do for i:=0 to RowCount do //Заголовки строк не трогаем for j:=1 to ColCount do //Заголовки столбцов не трогаем Cells[j, i]:=''; end;
procedure TForm1.FormPaint(Sender: TObject); begin with StringGrid1 do begin Cells[0,0]:='a[i]'; Cells[0,1]:='b[i]'; Cells[0,2]:='НОД(a[i],b[i])'; Cells[0,3]:='НОК(a[i],b[i])'; end; end;
procedure TForm1.Button2Click(Sender: TObject); var i, j: Integer; begin with StringGrid1 do begin j:=0; for i:=1 to ColCount do begin Cells[i,j+3]:=IntToStr(NOD(StrToInt(cells[i,j]),StrToInt(cells[i,j+1]))); Cells[i,j+4]:=IntToStr(NOK(StrToInt(cells[i,j]),StrToInt(cells[i,j+1]))); end; end; end;
end.
после запуска, ввода значений и нажатия кнопки посчитать выдает ошибку "Project Projectl.exe raised exception class EConvertError with message'" Is not a valid integer value1. Process stopped. Use Step or Run to continue." Не пойму в чем дело. и еще, не могли бы объяснить мне как сделать так чтобы количество столбцов в таблице можно было изменять во время работы