Recursion in DSA Python

Program 1

# Program for Addition of digit

# s=0
# def addition(n):
#     global s
#     if(n>0):
#         r=n%10
#         s=s+r
#         n=n//10
#         addition(n)

#     return(s)    

# # Main method code
# n=int(input("Enter a number"))
# x=addition(n)
# print("Addition of individual digit: ",x)


# # Program for Reverse of digit
# s=0
# def reverse(n):
#     global s
#     if(n>0):
#         r=n%10
#         s=s*10+r
#         n=n//10
#         reverse(n)

#     return(s)    

# # Main method code
# n=int(input("Enter a number"))
# x=reverse(n)
# print("Reverse of individual digit: ",x)
# if(x==n):
#     print("Number is Palindrome")
# else:
#     print("Number is not Palindrome")


# Program for Armstrong
s=0
def armstrong(n):
    global s
    if(n>0):
        r=n%10
        s=s+(r*r*r)
        n=n//10
        armstrong

    return(s)    

# Main method code
n=int(input("Enter a number"))
x=armstrong(n)
if(x==n):
    print("Number is Armstrong")
else:
   print("Number is not Armstrong")


# Program for factorial of Number
# def factorial(n):
#      if(n==1):
#        return n
#      else:
#        return(n*factorial(n-1))
        


# # Main Method
# n=int(input("Enter a number"))
# if(n<0):
#   print("Invalid Number")
# elif(n==0):
#   print("Factorial of 0 is 1")
# else:   
#   x=factorial(n)
#   print("Factorial is ",x)

 
#Program for print series
# i=1
# def printTable(n):
#     global i
#     if(i>10):
#         return
#     else:
#         print(n*i)
#         i=i+1
#         printTable(n)



# # #Main method
# n=int(input("Enter a Number"))
# printTable(n)


# Program for print series
# i=1
# def printSeries(n):
#     global i
#     if(i>n):
#         return
#     else:
#         print(i*i)
#         i=i+1
#         printSeries(n)




# #Main method
# n=int(input("Enter the limit"))
# printSeries(n)

 

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *