codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include<stdio.h> #include <stdlib.h> #define MAX 100 int Sieb_des_Eratosthenes() { long long unsigned int i, j, x; x = 0; char *array; array = calloc((MAX + 1), sizeof(char)); if (array==NULL) { printf("Error allocating memory!\n"); return -1; //return with failure } for(i = 2; i <= sqrt(MAX); i++) { if(array[i] == 0) { //array[i] = 1; x++; printf("prime %d ", i); for(j = i * i; j <= MAX; j += i) { array[j] = 1; } } } printf("Found: %d\n", x); free(array); array = NULL; return 0; } main() { return Sieb_des_Eratosthenes(); }
Private
[
?
]
Run code
Submit