Selasa, 28 Februari 2012

Program Bilangan Prima / Deret Bilangan Prima

Setelah postingan yang sebelumnya tentang Kalkulator Delphi 7 sederhana, kali ini saya akan bagikan kode/listing untuk program deret bilangan prima pada delphi 7.

Deret Bilangan Prima:




Menggunakan listing sebagai berikut:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    btn_proses: TButton;
    Label1: TLabel;
    Timer1: TTimer;
    Timer2: TTimer;
    btn_keluar: TButton;
    procedure btn_prosesClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure btn_keluarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  n:integer;

implementation

{$R *.dfm}

procedure TForm1.btn_prosesClick(Sender: TObject);
var
  a,b,c   : integer;
  p       : boolean;
begin
    ListBox1.Items.Clear;
  for a:=2 to 1000 do
  begin
  b:=2;
  p:=true;
  while (b<=a-1) and p do
    begin
    c:=a mod b;
    if c=0 then p:=false;
    b:=b+1;
    end;
  if p=true then
    ListBox1.Items.Add(IntToStr(a));
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Label1.Visible=true then
  Label1.Visible:=false
  else
  Label1.Visible:=true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  n:=0;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  n:=n+1;
  if n=1 then Form1.Caption:='D';
  if n=2 then Form1.Caption:=Form1.Caption+'e';
  if n=3 then Form1.Caption:=Form1.Caption+'r';
  if n=4 then Form1.Caption:=Form1.Caption+'e';
  if n=5 then Form1.Caption:=Form1.Caption+'t';
  if n=6 then Form1.Caption:=Form1.Caption+' ';
  if n=7 then Form1.Caption:=Form1.Caption+'B';
  if n=8 then Form1.Caption:=Form1.Caption+'i';
  if n=9 then Form1.Caption:=Form1.Caption+'l';
  if n=10 then Form1.Caption:=Form1.Caption+'a';
  if n=11 then Form1.Caption:=Form1.Caption+'n';
  if n=12 then Form1.Caption:=Form1.Caption+'g';
  if n=13 then Form1.Caption:=Form1.Caption+'a';
  if n=14 then Form1.Caption:=Form1.Caption+'n';
  if n=15 then Form1.Caption:=Form1.Caption+' ';
  if n=16 then Form1.Caption:=Form1.Caption+'P';
  if n=17 then Form1.Caption:=Form1.Caption+'r';
  if n=18 then Form1.Caption:=Form1.Caption+'i';
  if n=19 then Form1.Caption:=Form1.Caption+'m';
  if n=20 then Form1.Caption:=Form1.Caption+'a';
  if n=21 then
    begin
    Form1.Caption:=' ';
    n:=0;
    end;
end;

procedure TForm1.btn_keluarClick(Sender: TObject);
begin
  If(Application.MessageBox( 'Yakin Mau Keluar ?' ,'Informasi' ,mb_yesno)=idyes) then
close;
end;

end.






Tampilannya seperti ini :





1 komentar:

dhlondhenk mengatakan...

berkunjung kembali gan,buat buku tamu gan..biar gampang ninggalin jejak..hehehe..visited back n komengnya ya..thanks,hehee

Poskan Komentar

Warung Online