Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool suma(int cifra){
  6. int sumaBroja = 0;
  7. int bazaCifra = cifra;
  8. while(cifra != 0)
  9. {
  10. int temp = cifra%10;
  11. sumaBroja += (temp*temp*temp);
  12. cifra /= 10;
  13. }
  14. if(sumaBroja == bazaCifra) return true;
  15. return false;
  16. }
  17.  
  18. void ispis(int broj){
  19. for(int i = 1; i < broj; i++)
  20. if(suma(i)) cout << i << endl;
  21. }
  22.  
  23. int main()
  24. {
  25. int a = 0;
  26. cout << "Unesi prirodan broj: ";
  27. for(;;){
  28. cin >> a;
  29. if(a < 0 || a > 200) cout << "Pogresan unos!" << endl << "Unesi ponovo: ";
  30. else break;
  31. }
  32. ispis(a);
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement