Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[SOLVED] Prime Numbers


  • This topic is locked This topic is locked
1 reply to this topic

#1 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 43 posts

Posted 13 May 2012 - 02:53 PM

hi
i have a program that print prime numbers.
this is the code:


var
i,j,n:integer;
flag:boolean;
begin
write('Please Enter Number Of Information : ');
readln(n);
writeln;
for j:=2 to n do
begin
i:=2; flag:=true;
while i<=(j div 2) do
begin
if (j mod i)=0 then
flag:=false;
i:=i+1;
end;
if flag=true then
write(j,' ');
end;
writeln;

readln;
end.




now i have 2 questions:
1. on line 11th, i mean the code: " while i<=(j div 2) do "

why it is so? why the author wrote while i<=(j div 2) ???

2. and what does the "flag" variable do?

Thanks.
  • 1

#2 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 43 posts

Posted 13 May 2012 - 10:16 PM

i got the answer.
thanks.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download