Does anyone know how to write a program to find a happy number? I tried writing one, but it is apparently beyond me, because I cannot find a way through the problem. Here's what I have now.
I know, it is a bit of a mess, and I can probably condense some of it, but I haven't gotten around to it yet.
I was thinking about using recursion, since I just got done programming a Fibonacci program (the main point of the program was recursion), but I think that that would take too long, and maybe wouldn't be the most efficient way of doing this.
first: put the code, which computes sum of the squares of the digits into a separate function. This function would have a header like int sumOfDigitSquares(int n).
second: To check, if a given number is a happy number, recursion seems to be the simplest way (in coding effort; in computation time it will probably be not that good.). But when using recursion, there is one problem:
The sequence
n, sumOfDigitSquares(n), sumOfDigitSquares(sumOfDigitSquares(n)), ...
might never end up in 1.
To solve this is the real problem in this assignment. Maybe you have an idea about it?