delphi里实现edit1和edit2控件中分别输入任意两个整数,在edit3控件中输出两个数的最大公约数
procedureTForm1.Button1Click(Sender:TObject);varcount1,count2:Integer;beginifedit1.Te...
procedure TForm1.Button1Click(Sender: TObject);
var
count1 ,count2 : Integer ;
begin
if edit1.Text<>'' THEN
showmessage('请EDIT1输入数字')
end ;
else
if edit1.Text<>'' THEN
showmessage('请EDIT1输入数字')
// showmessage('请EDIT2EDIT1输入数字')
后面怎么写?
Function max_gy(a As Integer, b As Integer) '//求最大公约数的函数
var
i , Integer;
If a < b Then
For i = 1 To a
If a Mod i = 0 And b Mod i = 0 Then
max_gy = i
End If
Next i
Else
For i = 1 To b
If a Mod i = 0 And b Mod i = 0 Then
max_gy = i
End If
Next i
End If 展开
var
count1 ,count2 : Integer ;
begin
if edit1.Text<>'' THEN
showmessage('请EDIT1输入数字')
end ;
else
if edit1.Text<>'' THEN
showmessage('请EDIT1输入数字')
// showmessage('请EDIT2EDIT1输入数字')
后面怎么写?
Function max_gy(a As Integer, b As Integer) '//求最大公约数的函数
var
i , Integer;
If a < b Then
For i = 1 To a
If a Mod i = 0 And b Mod i = 0 Then
max_gy = i
End If
Next i
Else
For i = 1 To b
If a Mod i = 0 And b Mod i = 0 Then
max_gy = i
End If
Next i
End If 展开
1个回答
展开全部
procedure TForm1.Button1Click(Sender: TObject);
var
count1 ,count2 : Integer ;
begin
if edit1.Text='' THEN
begin
showmessage('请在EDIT1输入数字');
Abort;
end;
if edit2.Text='' THEN
begin
showmessage('请在EDIT2输入数字');
Abort;
end;
Edit3.Text := IntToStr(MAXDIVISOR(StrToInt(Edit1.Text),StrToInt(Edit2.Text)));
end;
function TForm1.MAXDIVISOR(N1, N2: INTEGER): INTEGER;
var
I:INTEGER;
begin
if N1>N2 then I:=N2 else I:=N1;
repeat
if (N1 mod I = 0) and (N2 mod I = 0) then Break;
I:= I - 1;
until
FALSE;
MAXDIVISOR:=I;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
var
count1 ,count2 : Integer ;
begin
if edit1.Text='' THEN
begin
showmessage('请在EDIT1输入数字');
Abort;
end;
if edit2.Text='' THEN
begin
showmessage('请在EDIT2输入数字');
Abort;
end;
Edit3.Text := IntToStr(MAXDIVISOR(StrToInt(Edit1.Text),StrToInt(Edit2.Text)));
end;
function TForm1.MAXDIVISOR(N1, N2: INTEGER): INTEGER;
var
I:INTEGER;
begin
if N1>N2 then I:=N2 else I:=N1;
repeat
if (N1 mod I = 0) and (N2 mod I = 0) then Break;
I:= I - 1;
until
FALSE;
MAXDIVISOR:=I;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询