0

Not Yet Answered # 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.

voken voken wylddev

0

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;
```

*Edited 3 Years Ago by Reverend Jim*: Fixed formatting

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;
```

*Edited 3 Years Ago by Reverend Jim*: Fixed formatting

0

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;

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

the function that I created to find the ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`