RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic Goto page Previous  1, 2 
View previous topic - View next topic  
Author Message
Adam
Mage


Joined: 30 Dec 2002
Posts: 416
Location: Australia

PostPosted: Tue Dec 19, 2006 10:24 am    Post subject: [quote]

The quickest way to find the primes is google.
_________________
https://numbatlogic.com
Back to top  
DrunkenCoder
Demon Hunter


Joined: 29 May 2002
Posts: 559

PostPosted: Fri Dec 22, 2006 12:28 pm    Post subject: [quote]

easyprimes.c
Code:

#include <stdio>
#include <math>
#include <memory>

int main()
{
   int max = 100, i, j, end = sqrt(max);
   char *sieve = malloc(max);
   memset(sieve, 0, max);
   for(i = 2; i < end; ++i)
   {
      if(!sieve[i])
      {
         for(j = i + i; j < max; j += i)
            sieve[j] = 1;
      }
   }
   for(i = 2; i != max; ++i)
      if(!sieve[i])
         printf("%d ", i);
}


If you try to compile it as c++ it will whine about type conversions.
Really that's the easiest I can think of.
_________________
If there's life after death there is no death, if there's no death we never live. | ENTP
Back to top  
Post new topic Reply to topic Page 2 of 2 All times are GMT
Goto page Previous  1, 2 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum