CBSE BOARD XII, asked by diana43, 10 months ago

write a program in python to check whether a number is a happy number or not . using recursion. do not use loop​

Answers

Answered by soulstar58
2
  • HOPE it helps to you
  • happy numbers always ends with 1
Attachments:

diana43: please is said using recursion no loops
soulstar58: trying
soulstar58: wait a while
diana43: yeah sure I will wait
diana43: I have been trying to get the answer since morning please if u could help
Answered by Anonymous
0

A program in python to check whether a number is a happy number or not is as follows:

def happy_number(x):  

   remainder = sum = 0

   while(x > 0):  

        remainder = x%10

        sum = sum + (remainder*remainder)

        x = x//10

   return sum

x = 19

res = x

while(res != 1 and res != 4) :  

       res = happy_number(res)

if (res == 1):  

       print(str (x) + " is a Happy Number");  

elif (res == 4):  

       print(str (x) + " is not a Happy Number");    

Similar questions