Q. Write a function that takes a number and tests if it is a prime number using recursion technique.
Answer =
count = 0
def prime(num,n) :
if n == num :
return num
else :
global count
if num % n == 0 :
count += 1
prime(num , n+1)
num = int(input("Enter a number : "))
prime( num , 2 )
if count > 0 :
print(num, "is not prime number")
else :
print(num , "is Prime number ")
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )