unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function NWD(a,b :Integer) :Integer;
var c :Integer;
begin
if (a<=0) or (b<=0) then
    raise Exception.Create('Liczby a i b muszą być większe od zera');
repeat
  c:=a mod b;
  a:=b;
  b:=c;
until b = 0;
Result:=a;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
try
  ShowMessage('Największy wspólny dzielnik: '+IntToStr(NWD(StrToInt(Edit1.Text),StrToInt(Edit2.Text))));
except
  on E: Exception do ShowMessage('Błąd: '+E.Message);
end;
end;

end.
