Advertisement
Guest User

KOTKI2

a guest
Nov 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int sumaKwadratowCyfrLiczby(int l)
  5. {
  6.     int suma = 0;
  7.     while (l != 0)
  8.     {
  9.         suma += (l % 10)*(l % 10);
  10.         l /= 10;
  11.     }
  12.     return suma;
  13. }
  14. bool czyWesola(int l)
  15. {
  16.     if (sumaKwadratowCyfrLiczby(l) == 1)
  17.         return true;
  18.     else if (sumaKwadratowCyfrLiczby(l) == 4)
  19.         return false;
  20.     else
  21.         return czyWesola(sumaKwadratowCyfrLiczby(l));
  22. }
  23. int main()
  24. {
  25.     int xD;
  26.     cin >> xD;
  27.     if (xD == 0)
  28.         return 0;
  29.     if (czyWesola(xD))
  30.         cout << 1;
  31.     else cout << 4;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement