Thread: Prime Numbers

  1. #1

    Unhappy Prime Numbers

    How would you go about coding a function to find the first x number of primes? I just can't figure out how to even start it. I'd greatly appriciate any help. Thanks

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    A simple way of working them out is to divide each number by every number lower than itself (except 1) and if none of the divisions result in a remainder of zero then you have a prime number (there are ways of speeding up this algorithm).

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Not the most efficient means of checking for primes, but it works.

    Actually, you do not need to check divisibility for all numbers less than the one you are currently testing, only all numbers less than or equal to the square root of the number.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4

    Talking Thanks

    Cool. Thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Replies: 18
    Last Post: 11-04-2005, 02:41 PM
  3. prime numbers, counters, help!
    By vege^ in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2003, 04:32 PM
  4. Prime numbers
    By Lazy Student in forum C Programming
    Replies: 12
    Last Post: 05-14-2002, 05:53 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM