I have written this code in Python to print Nth prime number.
Python Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from math import sqrt num=1 count=0 N=0 def prime(n): sqroot=int(sqrt(n)) j=2 while j<=sqroot: if n%j==0: return False j=j+1 return True N=int(input('Number : ')) while(True): num=num+1 if prime(num): count=count+1 if count==N: print(count,'th prime is ',num) break |
Output: