Happy Number
Try to solve the Happy Number problem.
We'll cover the following
Statement
Write an algorithm to determine if a number is a happy number.
We use the following process to check if a given number is a happy number:
- Starting with the given number , replace the number with the sum of the squares of its digits.
- Repeat the process until:
- The number equals , which will depict that the given number is a happy number.
- The number enters a cycle, which will depict that the given number is not a happy number.
Return TRUE if is a happy number, and FALSE if not.
Constraints
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy