主题:高手帮忙!!可以运行,但没有结果。谢谢啦 !
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
LblRes: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function Divisor(x,y:integer):integer;
public
{ public declarations }
end;
//在这之后进行函数声明
function Divisor(x,y:integer):integer;
var
Form1: TForm1;
//在这之前进行函数声明
implementation
{$R *.dfm}
//在这之后 进行函数定义
function Divisor(x,y:integer):integer;
var r:integer;
begin
r:=x mod y;
while r<>0 do
begin
x:=y; y:=r; r:=x mod y;
end ;
Divisor:=y;
end;
procedure TForm1.Button1Click(Sender: TObject);
var m,n,g:integer;
begin
n:=strtoint(Form1.Edit1.Text);
m:=strtoint(Form1.Edit2.Text);
g:=Divisor(n,m);
LblRes.Caption:='最大公约数: '+inttostr(g);
end ;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
LblRes: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function Divisor(x,y:integer):integer;
public
{ public declarations }
end;
//在这之后进行函数声明
function Divisor(x,y:integer):integer;
var
Form1: TForm1;
//在这之前进行函数声明
implementation
{$R *.dfm}
//在这之后 进行函数定义
function Divisor(x,y:integer):integer;
var r:integer;
begin
r:=x mod y;
while r<>0 do
begin
x:=y; y:=r; r:=x mod y;
end ;
Divisor:=y;
end;
procedure TForm1.Button1Click(Sender: TObject);
var m,n,g:integer;
begin
n:=strtoint(Form1.Edit1.Text);
m:=strtoint(Form1.Edit2.Text);
g:=Divisor(n,m);
LblRes.Caption:='最大公约数: '+inttostr(g);
end ;
end.