All pastes #541934 Raw Edit

Miscellany

public c v1 · immutable
·published 2007-06-05 17:44 UTC
rendered paste body
#include <stdio.h>#define ARRAY_SIZE 1000000#define DELETED    0long unsigned int sieve[ARRAY_SIZE];int main (){  printf ("Results of Sieve of Erastosthenes:\n\n");  fill_sieve();  delete_nonprimes();  print_primes();}fill_sieve (){  long unsigned int index;  for (index = 2; index < ARRAY_SIZE; index++)    sieve[index] = 1;}delete_nonprimes (){  long unsigned int index;  for (index = 2; index < ARRAY_SIZE; index++)    {      if (sieve[index] != DELETED)	delete_multiples_of_prime (index);    }}delete_multiples_of_prime (int prime){  long unsigned int index, multiplier = 2;  for (index = prime * multiplier; index < ARRAY_SIZE; index = prime * multiplier++)    sieve[index] = DELETED;}print_primes (){  long unsigned int index,total;    for (index = 2; index < ARRAY_SIZE; index++)    {      if (sieve[index] != DELETED)	total+=index;        printf("%d\n",total);    }  printf("\n\n");}