PROJECT BILANGAN PRIMA SEBANYAK N (DELPHI 7)
.......BILANGAN PRIMA SEBANYAK n......
EDIT1=MASUKAN,LISTBOX1=KELUARAN
procedure TForm1.Button1Click(Sender: TObject);
var i,a,b,c,d:integer;
p:boolean;
begin
a:=StrToInt(Edit1.Text);
For b:=2 to 1000 do
begin
i:=2;
p:=true;
while(i<=b-1)and p do
begin
c:=b mod i;
if c=0 then p:=false;
i:=i+1;
end;
if Listbox1.Items.count<a then
if p=true then
Listbox1.Items.Add('Bilangan Prima ke-'+IntToStr(Listbox1.Items.count+1)+'='+IntToStr(b));
end;
end;
end.
EDIT1=MASUKAN,LISTBOX1=KELUARAN
procedure TForm1.Button1Click(Sender: TObject);
var i,a,b,c,d:integer;
p:boolean;
begin
a:=StrToInt(Edit1.Text);
For b:=2 to 1000 do
begin
i:=2;
p:=true;
while(i<=b-1)and p do
begin
c:=b mod i;
if c=0 then p:=false;
i:=i+1;
end;
if Listbox1.Items.count<a then
if p=true then
Listbox1.Items.Add('Bilangan Prima ke-'+IntToStr(Listbox1.Items.count+1)+'='+IntToStr(b));
end;
end;
end.
0 comments: