Thread: C code to find the prime numbers from given set of numbers?

  1. #16
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by shan2014 View Post
    Anyway inorder to record the primes that have been found I would need to make an array right!
    Maybe. You need something that can hold multiple values. An array is one implementation option. There are others.

    Quote Originally Posted by Hodor View Post
    Hodor hardcodes all prime numbers into his source
    Personally, I only introduce prime numbers into source when I need prime numbers.

    How many primes have you hard coded so far? Doing all of them will take a fair while.
    Last edited by grumpy; 03-28-2014 at 11:16 PM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  2. #17
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by grumpy View Post
    How many primes have you hard coded so far? Doing all of them will take a fair while.
    50 million so far. It seems like it's a never ending task

  3. #18
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Wiki has an awesome page on this that explains it very well - Well enough to write a good algorithm Sieve of Eratosthenes - Wikipedia, the free encyclopedia

    Watch the table on the right.

    When you get the code working and you have answered the question you are after, have a go at this question Problem 10 - Project Euler - You will be shocked by the time difference between the two methods.
    Fact - Beethoven wrote his first symphony in C

  4. #19
    Registered User
    Join Date
    Nov 2012
    Posts
    157
    Quote Originally Posted by Click_here View Post
    When you get the code working and you have answered the question you are after, have a go at this question Problem 10 - Project Euler - You will be shocked by the time difference between the two methods
    .
    the first time i did problem 10 it took over 20 minutes to get the answer. yes, i am that bad...good algorithms saved me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 01-09-2013, 07:41 PM
  2. Replies: 1
    Last Post: 03-16-2012, 02:07 AM
  3. for loop to find prime numbers
    By lsecrease in forum C Programming
    Replies: 2
    Last Post: 03-30-2006, 01:58 AM
  4. for loop to find prime numbers
    By 1rwhites in forum C Programming
    Replies: 11
    Last Post: 10-21-2005, 10:37 AM

Tags for this Thread