J
jt780830
Unregistered / Unconfirmed
GUEST, unregistred user!
问题:输入一个整数,判断能否被3、5、7整除,并输出以下信息之一:(1)能同时被3、5、7整除;(2)能被其中两个数(指出哪2个);(3)能被其中一个数整除;(4)不能被整除;*********************************************************也许是人笨,用的办法也最笨,没什么好的方法:以下是本人代码(各位不要见笑,太菜了,个人学习中)。请没事的写下你们的方法:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Label1: TLabel
Edit1: TEdit
Button1: TButton
procedure Button1Click(Sender: TObject)
private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function Can3(a:integer):boolean;beginif (a mod 3)=0 thenresult:=trueelseresult:=false;end;function Can5(a:integer):boolean;beginif (a mod 5)=0 thenresult:=trueelseresult:=false;end;function Can7(a:integer):boolean;beginif (a mod 7)=0 thenresult:=trueelseresult:=false;end;procedure TForm1.Button1Click(Sender: TObject);var x:integer;begin x:=strtoint(edit1.text);if (Can3(x)=false) and (Can5(x)=false) and (Can7(x)=false) thenbeginshowmessage('不能被3、5、7中的任一数整除!');end;if (Can3(x)=true) and (Can5(x)=true) and (Can7(x)=true) thenshowmessage('能同时被3、5、7整除')else begin if (Can3(x)=true) and (Can5(x)=true) then showmessage('能同时被3和5整除') else if (Can3(x)=true) and (Can7(x)=true) then showmessage('能同时被3和7整除') else begin if (Can3(x)=true) then showmessage('能被3整除')
if (Can5(x)=true) then showmessage('能被5整除')
end
if (Can5(x)=true) and (Can7(x)=true) then showmessage('能同时被5和7整除') else if (Can7(x)=true) then begin showmessage('能被7整除')
end
end;end;end.
Edit1: TEdit
Button1: TButton
procedure Button1Click(Sender: TObject)
private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function Can3(a:integer):boolean;beginif (a mod 3)=0 thenresult:=trueelseresult:=false;end;function Can5(a:integer):boolean;beginif (a mod 5)=0 thenresult:=trueelseresult:=false;end;function Can7(a:integer):boolean;beginif (a mod 7)=0 thenresult:=trueelseresult:=false;end;procedure TForm1.Button1Click(Sender: TObject);var x:integer;begin x:=strtoint(edit1.text);if (Can3(x)=false) and (Can5(x)=false) and (Can7(x)=false) thenbeginshowmessage('不能被3、5、7中的任一数整除!');end;if (Can3(x)=true) and (Can5(x)=true) and (Can7(x)=true) thenshowmessage('能同时被3、5、7整除')else begin if (Can3(x)=true) and (Can5(x)=true) then showmessage('能同时被3和5整除') else if (Can3(x)=true) and (Can7(x)=true) then showmessage('能同时被3和7整除') else begin if (Can3(x)=true) then showmessage('能被3整除')
if (Can5(x)=true) then showmessage('能被5整除')
end
if (Can5(x)=true) and (Can7(x)=true) then showmessage('能同时被5和7整除') else if (Can7(x)=true) then begin showmessage('能被7整除')
end
end;end;end.