RadioNurshat

Armstrong's numbers

Sep 30th, 2020
1,223
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int power(int x, int i) {
  5.     if (i == 0) return 1;
  6.     int xx = 1;
  7.     for (int j = 0; j < i; j++) {
  8.         xx = xx * x;
  9.     }
  10.     return xx;
  11. }
  12. int main()
  13. {
  14.     int a = 0, b = 0;
  15.     cout << "Armstrong's numbers in ";
  16.     cout << "Range: ["; cin >> a; cout << ";"; cin >> b; cout << "]" << endl;
  17.     cout << "Armstong's numbers in this range:" << endl;
  18.     for (int i = a; i <= b; i++) {
  19.         int container = 0;
  20.         int ii = i;
  21.         while (ii > 0) {
  22.             container += power(ii % 10, 3);
  23.             ii = ii / 10;
  24.         }
  25.         if (i == container) {
  26.             cout << i << endl;
  27.         }
  28.     }
  29. }  
  30.  
  31.  
RAW Paste Data