Find first 250 Prime Number

This is a discussion on Find first 250 Prime Number within the C Programming forums, part of the General Programming Boards category; Hi Experts, I want to write a 'C' program to find the first 250 prime numbers and store them in ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    1

    Find first 250 Prime Number

    Hi Experts,

    I want to write a 'C' program to find the first 250 prime numbers and store
    them in an array and then print them out in columns on the screen.

    Can someone give me the coding if you already have it.

    Thanks.

    Howard

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    God I love when a semester is starting. See the homework FAQ. Why would you even consider taking a C class if you have no interest?

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    16
    Try implementing a solution; we will help you if you have any questions.

    I guess, you know what the prime number is.

    Cheers

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Code:
    main(x,y){for(;x++;)for(y=2;x%y;)++y/x&&printf("%d\n",x);}
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Any number that is not prime, is evenly divisible by a prime number.

    So, mark 2 as the first prime and try dividing all the following (odd) numbers from 3 upwards with the primes you have found so far. If it cannot be divided by any without remainder, add it to the list of primes.

    Continue, until you have 250 primes in the list.

    (Optimisation: you don't have to test-divide with all primes, but up to the square root of the value you are currently testing.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help, trying to find prime number
    By vampirekid.13 in forum C++ Programming
    Replies: 19
    Last Post: 05-02-2009, 03:29 PM
  2. prime number program with function
    By mackieinva in forum C Programming
    Replies: 17
    Last Post: 09-20-2007, 08:36 AM
  3. Prime Number stops after 29, but why?
    By Daveo in forum C Programming
    Replies: 22
    Last Post: 09-17-2004, 10:55 AM
  4. prime number.
    By tdoctasuess in forum C Programming
    Replies: 13
    Last Post: 05-13-2004, 08:03 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 04:56 PM

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