Advertisement
Guest User

Untitled

a guest
May 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int mocninkovac (int a)
  6. {
  7. int soucet = 0;
  8. int cifra =0;
  9. while (a>0)
  10. {
  11. cifra = a%10;
  12. a= a/10;
  13. soucet = soucet + cifra*cifra;
  14. }
  15. return soucet;
  16. }
  17.  
  18. bool zadovac (int cislo)
  19. {
  20. while (cislo != 1 && cislo != 89)
  21. {
  22. cislo = mocninkovac(cislo);
  23. }
  24. if (cislo == 89)
  25. {
  26. return true;
  27. }
  28. return false;
  29. }
  30.  
  31. int main()
  32. {
  33. int pocet = 0;
  34. for (int a = 1; a <= 10000000; a++)
  35. {
  36. if (zadovac(a))
  37. {
  38. pocet++;
  39. }
  40. }
  41. cout << "Hello World!" << endl;
  42. cout << pocet << endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement