unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var a,b : integer;
hasil : String;
begin
a:=StrToInt(Edit1.Text);
if a = 2 then hasil:='Bilangan Prima'
else if a < 2 then hasil:='Bukan Bilangan Prima'
else
begin
for b:=2 to a-1 do
begin
if a mod b = 0 then
begin
hasil:='Bukan Bilangan Prima';
break;
end
else hasil:='Bilangan Prima';
end;
end;
ShowMessage(hasil);
end;
end.
Desain form :
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var a,b : integer;
hasil : String;
begin
a:=StrToInt(Edit1.Text);
if a = 2 then hasil:='Bilangan Prima'
else if a < 2 then hasil:='Bukan Bilangan Prima'
else
begin
for b:=2 to a-1 do
begin
if a mod b = 0 then
begin
hasil:='Bukan Bilangan Prima';
break;
end
else hasil:='Bilangan Prima';
end;
end;
ShowMessage(hasil);
end;
end.
Desain form :
0 komentar:
Posting Komentar