procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d,e:integer;
begin
if (edit1.Text=”)or(edit2.Text=”)then
begin
showmessage(‘请输入两个数!’);
exit;
end;
a:=strtoint(edit1.Text);
http://www.gaodaima.com/?p=65973用Delphi编程求证两数互为质数_Delphi
b:=strtoint(edit2.Text);
//维持a大于b好进行下一步的算法
if a<b then
begin
c:=b;
b:=a ;
a:=c;
end;
//下面是程序判断部分
while d<>0 do
begin
c:=a div b;
d:=a-b*c; //取余数
a:=b;
b:=d;
end;
if a=1 then
begin
edit3.text:=’这两个数互为质数!’;
edit3.Color:=$00F4EEA2 ; //颜色设置
edit1.SetFocus;
end
else
begin
edit3.Text:= ‘这两个数不互为质数!’;
edit3.Color:= $008080FF; //颜色设置
edit1.SetFocus;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Text:=”;
edit2.Text:=”;
edit3.Text:=’请输入两个数。’;
edit3.Color:=$00B4E2D8;
end;
欢迎大家阅读《用DELPHI编程求证两数互为质数_Delphi》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码