heranchris0430

Armstrong Number

Apr 29th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  Armstrong Number
  4. //
  5. //  Created by Chris on 2017/4/29.
  6. //  Copyright ยฉ 2017ๅนด Chris. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <stdlib.h>
  11. #include <math.h>
  12.  
  13. using namespace std;
  14.  
  15. int main( ) {
  16.     int m1,m2,m3 = 0,m4 = 0,m5,m6[7] = { 0 },m7 = 0,g1 = 0,i,n2,n3;
  17.     while(cin >> n2 >> n3){
  18.         m7 = 0;
  19.         while (n2 < n3){
  20.             m1 = n2;
  21.             g1 = 0;
  22.             m4 = 0;
  23.             m2 = n2;
  24.             m5 = n2;
  25.             while (m2 != 0){
  26.                 m2 /= 10;
  27.                 g1 ++;
  28.             }
  29.             for (i = 0;i < g1;i++){
  30.                 m6[ i ] = m5 % 10;
  31.                 m5 /= 10;
  32.             }
  33.             for (i = 0;i < g1;i++){
  34.                 m3 = pow (m6[i],g1);
  35.                 m4 = m3 + m4;
  36.             }
  37.             if (m1 == m4){
  38.                 cout << m1 << " ";
  39.                 m7++;
  40.             }
  41.             n2 += 1;
  42.         }
  43.         if (m7 == 0)
  44.             cout << "none";
  45.         cout << endl;
  46.     }
  47. }
Add Comment
Please, Sign In to add comment