954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to decifer from prime or not prime numbers

hello there im sorry i can not help you with your problem and like i said i am very sorry i am looking for some help myself first i do not know how to post a question on here second i need help with a program it is in pascal and i need it to decifer from prime or not prime between the numbers 1 and 1000 so plz ne who reads this help i know pascal but im in college so its their thing ne one plz help me thanx again.

chickenmcnugget
Newbie Poster
17 posts since Mar 2007
Reputation Points: 9
Solved Threads: 0
 

procedure TForm1.Button1Click(Sender: TObject);
Function is_prime(r:integer):boolean;
var j:integer;
begin
if (r=1) or (r=2) then begin result:=true; exit; end;
for j := 2 to r-1 do begin
if (r mod j=0) then begin
result:=false;//not prime
exit;
end;
end;
result := true;//prime
end;

var j,r,k,a,b,c:integer;
red:boolean;

begin
listbox1.Clear ;
listbox2.Clear ;
listbox3.Clear ;
{start value} i:=strtoint(combobox1.Text );
{end value} j:= strtoint(combobox2.Text);
for i:=i to j do
begin
if (i mod 2=0) then
listbox1.Items.Add(inttostr(i))
else
listbox2.Items.Add(inttostr(i));
if is_prime(i) then listbox3.Items.Add(inttostr(i));
end;
end;

voken
Newbie Poster
2 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

procedure TForm1.Button1Click(Sender: TObject);
Function is_prime(r:integer):boolean;
var j:integer;
begin
if (r=1) or (r=2) then begin result:=true; exit; end;
for j := 2 to r-1 do begin
if (r mod j=0) then begin
result:=false;//not prime
exit;
end;
end;
result := true;//prime
end;

var j,r,k,a,b,c:integer;
red:boolean;

begin
listbox1.Clear ;
listbox2.Clear ;
listbox3.Clear ;
{start value} i:=strtoint(combobox1.Text );
{end value} j:= strtoint(combobox2.Text);
for i:=i to j do
begin
if (i mod 2=0) then
listbox1.Items.Add(inttostr(i))
else
listbox2.Items.Add(inttostr(i));
if is_prime(i) then listbox3.Items.Add(inttostr(i));
end;
end;

voken
Newbie Poster
2 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 
FlamingClaw
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

try this function below and see if it works..

function IsPrime(const n: int64): boolean;
var
i: cardinal;
en: extended;
begin
if n <> 2 then begin
en := n;
for i := 2 to round(sqrt(en)) do
if n mod i = 0 then begin
result := false;
exit;
end;
end;
result := n > 0; // or > 1
end;

wylddev
Newbie Poster
9 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You