Back to problems

Happy Number

Algorithm · Snowflake · Easy

Problem: Happy Number For a positive integer n, decide if it is happy. A number is considered happy under this procedure: Begin with a positive integer. Compute a new value by adding the squares of all its digits. Continue applying that transformation. The starting value is happy when the sequence reaches 1. It is unhappy when the sequence repeats in a loop that never reaches 1. Write a program that accepts an integer n and reports whether it is happy. Input Format Output…

Checking your access…