Here let be listed exercises for the readers of the wiki. You can allow yourself to as many helpers and resources as you find challenging: with each problem you should either find out you know the solution or learn something new while solving it.
Problems in each category should follow from easiest to most difficult. The listed solutions may not be the only possible solutions, just one of them.
1:
// Sieve of Eratosthenes algorithm, one possible way to generate prime numbers
#include <stdio.h>
#define N 1000
char primeMap[N];
int main(void)
{
int primeCount = 0;
for (int i = 0; i < N; ++i)
primeMap[i] = 1;
for (int i = 2; i < N; ++i)
{
if (primeMap[i])
{
primeCount++;
printf("%d\n",i);
}
int j = i;
while (1) // mark all multiples of i non-primes
{
j += i;
if (j >= N)
break;
primeMap[j] = 0; // can't be a prime
}
}
printf("prime count under %d: %d\n",N,primeCount);
return 0;
}
All content available under CC0 1.0 (public domain). Send comments and corrections to drummyfish at disroot dot org.