Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shishire@achilles:~$ cat sieve.c
- #include <stdlib.h>
- #include <math.h>
- char*
- eratosthenes(int n, int *c)
- {
- char* sieve;
- int i, j, m;
- if(n < 2)
- return NULL;
- *c = n-1; /* primes count */
- m = (int) sqrt((double) n);
- /* calloc initializes to zero */
- sieve = calloc(n+1,sizeof(char));
- sieve[0] = 1;
- sieve[1] = 1;
- for(i = 2; i <= m; i++)
- if(!sieve[i])
- for (j = i*i; j <= n; j += i)
- if(!sieve[j]){
- sieve[j] = 1;
- --(*c);
- }
- return sieve;
- }
- int main(int argc, char *argv)
- {
- int *array, n=0xFFFF;
- array =(int *)malloc(sizeof(int));
- eratosthenes(n,array);
- return 0;
- }
- shishire@achilles:~$ gcc -o sieve -static -static-libgcc -static-libstdc++ -lm sieve.c
- /tmp/ccgpiyqD.o: In function `eratosthenes':
- sieve.c:(.text+0x35): undefined reference to `sqrt'
- collect2: error: ld returned 1 exit status
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement