A happy number is a positive integer for which the sum of the squares of the digits eventually leads to 1.
For example, 13 is a happy number since 1*1 + 3*3 = 10 and 1*1 + 0*0 = 1.
Here's the algorithm:
1. Start with a positive integer n.
2. Dissect it into digits.
3. Square the digits and add them up.
4. You get a new number m.
5. If m = 1, n is happy; otherwise set n = m and repeat from step #1.
6. If you run into a loop, n is not a happy number.
Design a solution to the problem of "How to find a Happy Number." If a number is Happy, it will converge to 1. However, if it is not Happy, it will never converge, but will continue to "loop".
You must write a recursive solution to the Happy Number problem.
Create a menu that has the following choices:
1) Show Happy Sequence for a number
2) Show all Happy Numbers in a range
3) Exit
Your program will ask for a number and determine if that number is Happy, and report back to the user and print each number of the sequence. Example: If the user wants to know if 13 is a Happy Number, the program might print:
Sequence: 13, 10, 1 - Happy
Here are more examples:
input: 13000
output: 13000, 10, 1 - Happy
input: 643
output: 643, 61, 37, 58, 89, 145, 42, 20, 4, 16, 37 - Not Happy
Here is a summary of requirements:
1) You must prompt the user for a positive integer. Check the input to make sure it is positive. If the integer is not positive, continue to prompt for a positive number.
2) Your program must print out each intermediate numbers.
Your program will ask the user for 2 integers. Your program will list all happy numbers that fall in between those 2 integers inclusively and print a dot if the number is not happy. Make sure to format the output nicely so there are multiple lines and they line up nicely on both sides. Here is an example:
Welcome to the Happiest Number place on Earth!
Please enter 2 integers and I will tell you all the Happy Numbers between those numbers:
Number 1: 1
Number 2: 1000
1.....7..10..13.....19...23....28..3132...........44....49..
................68.70........79..82...86....91..94..97..100.
.103.....109...................129130..133.....139..........
.................167........176...........188.190.192193....
.....203....208..........219......226...230.....236..239....
..................262263................280..........291.293
.......301302.......310..313.....319320.....326..329.331....
..338.................356.....362..365.367368.......376..379
...383..386....391392....397......404....409................
..............440.....446.................464....469........
478........487..490.....496.................................
......536...................556......563.565566.............
............................608........617....622623........
632..635.637638.....644....649...653.655656........665.....671
.673......680..683..........694.....700........709......716.
..................736..739........748............761.763....
................784.....790..793........802...806...........
818.820............833..836..........847............860..863
..........874......881......888..........899.901..904..907..
910.912913.......921.923.......931932....937..940.....946...
..............964.....970..973...............989........998.
1000