DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: 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
|
|