Guest User

Untitled

a guest
Jun 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4.  
  5. bool isarmstrong(int i) {
  6.         int zbytek = 0;
  7.         int suma = 0;
  8.         int delenec = i;
  9.  
  10.         while(delenec != 0) {
  11.                 zbytek = delenec % 10;
  12.                 delenec /= 10;
  13.                 suma += pow((float)zbytek, (int)3);
  14.         }
  15.  
  16.         if(suma == i)
  17.                 return true;
  18.         return false;
  19. }
  20.  
  21. int main() {
  22.        
  23.         int upperbound = 0;
  24.  
  25.         std::cin >> upperbound;
  26.  
  27.         int i = 1;
  28.         while(i <= upperbound) {
  29.                 if(isarmstrong(i)) {
  30.                         std::cout << i << " ";
  31.                 }
  32.                 i++;
  33.         }
  34.  
  35.         std::cin.get();
  36.         std::cin.get();
  37.  
  38.         return 0;
  39.  
  40.        
  41. }
Add Comment
Please, Sign In to add comment