Question: I need help with this code in C: 1 Description Consider any positive integer S 0 . Let S 1 be the sum of the

I need help with this code in C: 1 Description
Consider any positive integer S0. Let S1 be the sum of the square of its digits. Similarly, S2 is defined
as the sum of the squares of the digits of S1 and so on. If Si =1, for any i >=1, then the initial number (S0) is said to be
a happy number. A number that is not happy is called an unhappy number. Take S0=7, for example. We then have: 7->49->97->
130->10->1. This means that 7 is a happy number. The number 4, on the other hand, is unhappy, since: 4->16->37->58->89->145->42->20->4.
This sequence will obviously never lead to obtaining the value 1, which is necessary for a happy number (look how unhappy it is).
You may have guessed that already (right?). You'll have to write a program to check whether the given numbers are happy!
2 Input
Input will be made from the keyboard and will consist of several input cases. The first line of the input will specify the number
of inputs to be processed, each of which is shown on a subsequent line. You can assume
that the numbers provided as input (each number provided as input will be an S0 value) will be less than 109
.
3 Output
You must determine whether each of the numbers provided as input is happy or unhappy by printing one of the following messages, according to what you determine about the number:
- Input #p: n is a happy number.
- Input #p: n is an unhappy number.
Where p is the input number (starting at 1) and n is the number originally supplied.
4 Input example
3
7
4
13
5 Sample Output
Input #1: 7 is a happy number.
Input #2: 4 is an unhappy number.
Input #3: 13 is a happy number.
and the outputs need to be exactly the same of the sample but of course the numbers wont be the same so just the phrase

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!