# Happy Numbers make Happy Programmers ! :-)

Here is one question which one of my students, Vedant Sahai asked me. It appeared in his computer subject exam of his recent ICSE X exam (Mumbai):

write a program to accept a number from the user, and check if the number is a happy number or not; and the program has to display a message accordingly:

A Happy Number is defined as follows: take a positive number and replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (one). If the number ends with 1, then it is called a happy number.

For example: 31

Solution : 31 replaced by $3^{2}+1^{2}=10$ and 10 replaced by $1^{2}+0^{2}=1$.

So, are you really happy? 🙂 🙂 🙂

Cheers,

Nalin Pithwa.

## 2 thoughts on “Happy Numbers make Happy Programmers ! :-)”

1. Oh….this certainly is “composition of happinesses” ! ha…ha…ha…lol…thanks a lot …

Like

This site uses Akismet to reduce spam. Learn how your comment data is processed.