Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Prime numbers (Eratosthenes)
I need to implement the following algorithm where P needs to be modelled af
an array of booleans ( booleans[]P = new boolean[n + 1]).

But how do I write this in the {} thats gonna be executed as long as 2*i<=
n??

for (i = 2; 2*i <=n; i = i + 1)
//{remove from P all multiples of i};
//print the contents of P





Report this thread to moderator Post Follow-up to this message
Old Post
JS
12-30-04 01:58 AM


Re: Prime numbers (Eratosthenes)
On Wed, 29 Dec 2004 22:05:42 +0100
"JS" <dsa.@asdf.com> wrote:

>
> I need to implement the following algorithm where P needs to be
> modelled af an array of booleans ( booleans[]P = new boolean[n + 1]).
>
> But how do I write this in the {} thats gonna be executed as long as
> 2*i<= n??
>
> for (i = 2; 2*i <=n; i = i + 1)
> //{remove from P all multiples of i};
> //print the contents of P

First, you might wish to reconsider the loop length. It will be
sufficient to mark all multiples of primes less then the square root of
n. Then you iterate over all multiples of the current i smaller then
(or equal to) n, marking each such multiple as false.

What, you wanted me to do your homework for you? :-P Its all written
down there, and i bet in your textbook as well.

--
In pioneer days they used oxen for heavy pulling, and when one ox
couldn't budge a log, they didn't try to grow a larger ox. We shouldn't
be trying for bigger computers, but for more systems of computers.
--- Rear Admiral Grace Murray Hopper

Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Schulz
12-30-04 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:48 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.