Loading...
Searching...
No Matches
primes_array.c

Generate an array of primes.

Generate an array of primes.

#include <primesieve.h>
#include <stdio.h>
int main(void)
{
uint64_t start = 0;
uint64_t stop = 1000;
size_t i;
size_t size;
/* Get an array with the primes <= 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;
/* Get an array with 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.h
primesieve C API.
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:43
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_free
void primesieve_free(void *primes)
Deallocate a primes array created using the primesieve_generate_primes() or primesieve_generate_n_pri...