C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
finding prime numbers.. Posted by Mavrix on 24 Sept 2006 at 12:19 PM
Hey all, I'm on an assignment and a bit lost. I'm supposed to write a program that finds the average of all prime numbers between 1 and 100 and prints this average to screen:


I can do it all easily enough, except for finding prime numbers.. I suspect it's something to do with the modulas (remainder) operator but not real sure how to lay it out, any help is appreciated guys & gals. ^^
Report
Re: finding prime numbers.. Posted by Pruyque on 27 Sept 2006 at 12:43 PM
: Hey all, I'm on an assignment and a bit lost. I'm supposed to write a program that finds the average of all prime numbers between 1 and 100 and prints this average to screen:
:
:
: I can do it all easily enough, except for finding prime numbers.. I suspect it's something to do with the modulas (remainder) operator but not real sure how to lay it out, any help is appreciated guys & gals. ^^
:

Here's an easy (and fast) algorithm (pen and paper implementation;) for finding primes up to a certian number:

// I don't know if 1 is a prime number, so we'll skip it ;)
write down the numbers from 2 to lets say 100.
put a circle around 2 and cross out all higher multiples of 2 (4, 6, 8 etc)
while there are numbers without a circle or a cross:
{
 find the next noncrossed number and put a circle around it, and cross out all higher multiples of this number
}
all numbers with circles around them are prime


good luck,
Pruyque
Report
Re: finding prime numbers.. Posted by Mavrix on 30 Sept 2006 at 8:35 AM
I never got back to you to say thanks, was able to figure it out. :)



: : Hey all, I'm on an assignment and a bit lost. I'm supposed to write a program that finds the average of all prime numbers between 1 and 100 and prints this average to screen:
: :
: :
: : I can do it all easily enough, except for finding prime numbers.. I suspect it's something to do with the modulas (remainder) operator but not real sure how to lay it out, any help is appreciated guys & gals. ^^
: :
:
: Here's an easy (and fast) algorithm (pen and paper implementation;) for finding primes up to a certian number:
:
:
: // I don't know if 1 is a prime number, so we'll skip it ;)
: write down the numbers from 2 to lets say 100.
: put a circle around 2 and cross out all higher multiples of 2 (4, 6, 8 etc)
: while there are numbers without a circle or a cross:
: {
:  find the next noncrossed number and put a circle around it, and cross out all higher multiples of this number
: }
: all numbers with circles around them are prime
: 

:
: good luck,
: Pruyque
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.