Print Prime Numbers from 1 to N | Sieve of Eratosthenes

Write a program to print prime numbers from 1 to N (where n is an integer).

This problem can also be asked like,

i) How to print prime numbers from 1 to 100.

ii) How to print prime numbers from 1 to 1000 etc.

In this tutorial, we are going to learn how to print prime numbers efficiently using sieve algorithm.

Suppose the value of N is 10, So the prime numbers between 1 to 10 is 2, 3, 5, 7.

Before writing a code, let’s first first understand, what is prime number?