Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <vector>
- using namespace std;
- typedef unsigned long long int ull;
- void HappyOrNOt(ull n, ull n_copy, ull x)
- {
- // int value = n;
- ull result = 0;
- vector <ull> hold;
- while(n != 0)
- {
- hold.push_back(n % 10);
- n = n/10 ;
- }
- for(ull i = 0; i < hold.size(); i++)
- {
- result += hold.at(i)*hold.at(i);
- }
- if(result == 1)
- cout << "Case #" << x + 1 << ": " << n_copy << " is a Happy number." ;
- else if (result == n_copy)
- cout << "Case #" << x + 1 << ": " << n_copy << ": is an Unhappy number." ;
- else HappyOrNOt(result, n_copy, x);
- }
- int main()
- {
- int cases, n;
- cin >> cases;
- for(int x = 0; x < cases; x++)
- {
- cin >> n;
- HappyOrNOt(n, n, x);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement