GeeksforGeeksSolution ForHardDomain .Below You Can Find The Solution OfSchoolBasic ,Easy ,Medium. OrHackerrank SolutionYou Can Also Direct Submit Your Solution toGeeksforgeeksSame Problem .You Need to login then you can submit you answers

**Problem :-**Happy Number

**Submit Your Solution :-**

**Click Here**

**Solution :-**

#include <bits/stdc++.h>

using namespace std;

int numSquareSum(int n)

{

int squareSum = 0;

while (n)

{

squareSum += (n % 10) * (n % 10);

n /= 10;

}

return squareSum;

}

bool isHappynumber(int n)

{

int slow, fast;

slow = fast = n;

do

{

slow = numSquareSum(slow);

fast = numSquareSum(numSquareSum(fast));

}

while (slow != fast);

return (slow == 1);

}

int main()

{

int t;

cin>>t;

while(t--)

{

int n;

cin>>n;

if (isHappynumber(n))

cout <<"1\n";

else

cout <<"0\n";

}

return 0;

}

**Output:-**

## 0 Comments: