write a program to input a number and check if it is a happy number or not using user defined function.
Answers
Answer:
Input: n = 19
Output: True
19 is Happy Number,
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.
Input: n = 20
Output: False
Explanation:
// method return true if n is Happy Number
// numSquareSum method is given in below detailed code snippet
int isHappyNumber(int n)
{
set<int> st;
while (1)
{
n = numSquareSum(n);
if (n == 1)
return true;
if (st.find(n) != st.end())
return false;
st.insert(n);
}
}
plz mark it as a brainliest
Answer:
Answer:
Input: n = 19
Output: True
19 is Happy Number,
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.
Input: n = 20
Output: False
Explanation:
// method return true if n is Happy Number
// numSquareSum method is given in below detailed code snippet
int isHappyNumber(int n)
{
set<int> st;
while (1)
{
n = numSquareSum(n);
if (n == 1)
return true;
if (st.find(n) != st.end())
return false;
st.insert(n);
}
}