Matthew Gray

NCSU ‘19 - Programmer

C Practice: Implementing Sieve of Eratosthenes

While sitting in my Computer Science class today, nearly finished with high school, I was playing around on one of my favorite sites to practice programming, Project Euler. After solving about 45 problems a few years ago I drifted away from it as I got busy with high school and actually began to value the number of hours of sleep I got per night more than the number of problems I solved. Now, almost entirely finished with high school, I have some time to not only practice programming again, but to tackle Project Euler as well.

When I worked in the past on problems that involved prime numbers, primality tests, and the like I came upon something called Sieve of Eratosthenes which, in short, is an algorithm for finding which numbers in a range from 2 to n are prime. Now that I am working on learning C, I thought implementing and writing about it wouldn’t hurt so enjoy.

The steps of the...

Continue reading →