Sieve of Eratosthenes and ADT
Sieve of Eratosthenes and ADT
According to the algorithm we will mark all the numbers which are divisible by
2 and are greater than or equal to the square of it.
Now we move to our next unmarked number 3 and mark all the numbers
which are multiples of 3 and are greater than or equal to the square of it.
We move to our next unmarked number 5 and mark all multiples of 5 and are
greater than or equal to the square of it.
We continue this process and our final table will look like below:
So the prime numbers are the unmarked ones: 2, 3, 5, 7, 11, 13, 17, 19, 23,
29, 31, 37, 41, 43, 47.
Que 4.3. Write a Python program to print all primes smaller than or
equal to n using Sieve of Eratosthenes.
void SieveOfEratosthenes(int n)
// finally be false if i is
// then it is a prime
if (prime[p] == true)
// of p greater than or
prime[i] = false;
}
// Print all prime numbers
if (prime[p])
// Driver Code
int main()
int n = 30;
SieveOfEratosthenes(n);
return 0;
Code: https://citizenchoice.in/course/Python-Programing/Unit%204/Modules-
Import-Statements-and-Abstract-Data-Types