?? unit3.pas
字號:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var
a,b,c,f:Integer;
begin
f:=0;
for a:=1 to 16 do
begin
for b:=1 to 25 do
begin
for c:=1 to 50 do
if((3*a+2*b+c=50)and(a+b+c=30)) then
begin
Edit1.Text:=IntToStr(a);
Edit2.Text:=IntToStr(b);
Edit3.Text:=IntToStr(c);
f:=1;
break; // 找到一組答案時,跳出循環(huán)體
end;
end;
if(f=1) then break;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
end;
end.