filmov
tv
C Numbers 13: Check if a number is a Happy Number [C Programming]

Показать описание
Write a program in C to check a number is a Happy or not.
Expected Output :
Input a number : 13
13 is a Happy number
==========================
What is a Happy number?
A number is called happy if it leads to 1 afte a sequence of steps wherein each step number is replaced by the sum of squares of its digit and that is if we start with Happy Number and keep replacing it with digits square sum, we reach 1.
Example:
Input : n = 19
Output : True
19 is Happy Number
Explanation :
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1
As we reached to 1, 19 is a happy number
=================================================
Expected Output :
Input a number : 13
13 is a Happy number
==========================
What is a Happy number?
A number is called happy if it leads to 1 afte a sequence of steps wherein each step number is replaced by the sum of squares of its digit and that is if we start with Happy Number and keep replacing it with digits square sum, we reach 1.
Example:
Input : n = 19
Output : True
19 is Happy Number
Explanation :
1^2 + 9^2 = 82
8^2 + 2^2 = 68
6^2 + 8^2 = 100
1^2 + 0^2 + 0^2 = 1
As we reached to 1, 19 is a happy number
=================================================