用DELPHI编程求证两数互为质数
点击次数:62 次 发布日期:2008-11-09 08:41:35 作者:源代码网
|
源代码网推荐 var 源代码网推荐 a,b,c,d,e:integer; 源代码网推荐 begin 源代码网推荐 if (edit1.Text="")or(edit2.Text="")then 源代码网推荐 begin 源代码网推荐 showmessage("请输入两个数!"); 源代码网推荐 exit; 源代码网推荐 end; 源代码网推荐 a:=strtoint(edit1.Text); 源代码网推荐 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; 源代码网推荐 源代码网供稿. |
