Write a program to print prime numbers in a range using Sieve of Eratosthenes.


Topic: Write a program to print prime numbers in a range using Sieve of Eratosthenes.

Solution

n=int(input("Enter upper limit of range: "))
sieve=set(range(2,n+1))
while sieve:
    prime=min(sieve)
    print(prime,end="\t")
    sieve-=set(range(prime,n+1,prime))
 
print()



List all Python Programs