store_primes_in_array.c

Store primes in a C array.

#include <primesieve.h>
#include <stdio.h>
int main()
{
uint64_t start = 0;
uint64_t stop = 1000;
size_t i;
size_t size;
/* store the primes below 1000 */
int* primes = (int*) primesieve_generate_primes(start, stop, &size, INT_PRIMES);
for (i = 0; i < size; i++)
printf("%i\n", primes[i]);
primesieve_free(primes);
uint64_t n = 1000;
/* store the first 1000 primes */
primes = (int*) primesieve_generate_n_primes(n, start, INT_PRIMES);
for (i = 0; i < n; i++)
printf("%i\n", primes[i]);
primesieve_free(primes);
return 0;
}
primesieve_free
void primesieve_free(void *primes)
Deallocate a primes array created using the primesieve_generate_primes() or primesieve_generate_n_pri...
primesieve.h
primesieve C API. primesieve is a library for fast prime number generation. In case an error occurs e...
primesieve_generate_primes
void * primesieve_generate_primes(uint64_t start, uint64_t stop, size_t *size, int type)
Get an array with the primes inside the interval [start, stop].
primesieve_generate_n_primes
void * primesieve_generate_n_primes(uint64_t n, uint64_t start, int type)
Get an array with the first n primes >= start.
INT_PRIMES
@ INT_PRIMES
Generate primes of int type.
Definition: primesieve.h:40