Prime numbers

This is a discussion on Prime numbers within the C Programming forums, part of the General Programming Boards category; hello peepz... does anyone knows what the formula on getting the prime number in the c code ??...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    4

    Prime numbers

    hello peepz...
    does anyone knows what the formula on getting the prime number in the c code??

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Just loop through each number below it (below half of it, really) modding by that number to make sure there is a remainder in all of them. There are more efficient algos to do it, but unless your planning on finding the largest prime numbers in existence, I wouldn't worry about it.
    Last edited by SlyMaelstrom; 09-13-2006 at 02:57 AM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    4
    what if the input is to numbers then you have to output the prime numbers from first input until the 2nd input???

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Show some code... we're not here to give you answers...

    I'll say this... there is a specific kind of loop where you can specify lower bounds and upper bounds right in the statement.
    Sent from my iPadŽ

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    You can also look into Fermat's little theorem if you want to get a solid boost in efficiency.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    75
    Quote Originally Posted by teves16
    hello peepz...
    does anyone knows what the formula on getting the prime number in the c code??
    Google it!

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, 06: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, 06:53 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21