4. Assignment 12
WAP to print all prime numbers <= ‘num’ using Sieve of
Eratosthenes method.
5. Assignment 12
WAP to print all prime numbers <= ‘num’ using Sieve of
Eratosthenes method.
Input:
6. Assignment 12
WAP to print all prime numbers <= ‘num’ using Sieve of
Eratosthenes method.
Input: Read integer ‘num’
7. Assignment 12
WAP to print all prime numbers <= ‘num’ using Sieve of
Eratosthenes method.
Input: Read integer ‘num’
Output:
8. Assignment 12
WAP to print all prime numbers <= ‘num’ using Sieve of
Eratosthenes method.
Input: Read integer ‘num’
Output: Print the prime numbers less than or equal to ‘num’
13. Assignment 12
Sieve of Eratosthenes:-
⮚The sieve of Eratosthenes is one of the most efficient ways to
find all of the smaller primes.
14. Assignment 12
Sieve of Eratosthenes:-
⮚The sieve of Eratosthenes is one of the most efficient ways to
find all of the smaller primes.
⮚Generate a list of integers from 2 to 20
15. Assignment 12
Sieve of Eratosthenes:-
⮚The sieve of Eratosthenes is one of the most efficient ways to
find all of the smaller primes.
⮚Generate a list of integers from 2 to 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
16. Assignment 12
Sieve of Eratosthenes:-
⮚The sieve of Eratosthenes is one of the most efficient ways to
find all of the smaller primes.
⮚Generate a list of integers from 2 to 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
17. Assignment 12
Sieve of Eratosthenes:-
⮚The first number in the list is 2; cross out every multiples of
2.
20. Assignment 12
Sieve of Eratosthenes:-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X X X
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
21. Assignment 12
Sieve of Eratosthenes:-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X X X
X X
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
22. Assignment 12
Sieve of Eratosthenes:-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X X X
X X X
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
23. Assignment 12
Sieve of Eratosthenes:-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X X X
X X X X
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
24. Assignment 12
Sieve of Eratosthenes:-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X X X
X X X X X
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
25. Assignment 12
Sieve of Eratosthenes:-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X X X
X X X X X X
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
26. Assignment 12
Sieve of Eratosthenes:-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
X X X
X X X X X X X
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
28. Assignment 12
Sieve of Eratosthenes:-
⮚ Can we remove array elements?
We cannot remove array elements
29. Assignment 12
Sieve of Eratosthenes:-
⮚ Can we remove array elements?
We cannot remove array elements
⮚What can be done?
30. Assignment 12
Sieve of Eratosthenes:-
⮚ Can we remove array elements?
We cannot remove array elements
⮚What can be done?
Make it as 0
31. Assignment 12
Sieve of Eratosthenes:-
⮚ Can we remove array elements?
We cannot remove array elements
⮚What can be done?
Make it as 0
2 3 0 5 0 7 0 9 0 11 0 13 0 15 0 17 0 19 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
32. Assignment 12
Sieve of Eratosthenes:-
⮚The next number in the list is 3, make multiples of 3 as 0
2 3 0 5 0 7 0 9 0 11 0 13 0 15 0 17 0 19 0
i
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
33. Assignment 12
Sieve of Eratosthenes:-
⮚ The next number in the list is 3, make multiples of 3 as 0
2 3 0 5 0 7 0 0 0 11 0 13 0 15 0 17 0 19 0
i
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
34. Assignment 12
Sieve of Eratosthenes:-
⮚ The next number in the list is 3, make multiples of 3 as 0
2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0
i
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
35. Assignment 12
Sieve of Eratosthenes:-
⮚The next number which is not removed is 5.
2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i
36. Assignment 12
Sieve of Eratosthenes:-
⮚ The next number which is not removed is 5.
⮚It is not necessary to remove multiples of 5, because all non
prime numbers has been removed.
2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
i