Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Armstrong Number
- //
- // Created by Chris on 2017/4/29.
- // Copyright ยฉ 2017ๅนด Chris. All rights reserved.
- //
- #include <iostream>
- #include <stdlib.h>
- #include <math.h>
- using namespace std;
- int main( ) {
- int m1,m2,m3 = 0,m4 = 0,m5,m6[7] = { 0 },m7 = 0,g1 = 0,i,n2,n3;
- while(cin >> n2 >> n3){
- m7 = 0;
- while (n2 < n3){
- m1 = n2;
- g1 = 0;
- m4 = 0;
- m2 = n2;
- m5 = n2;
- while (m2 != 0){
- m2 /= 10;
- g1 ++;
- }
- for (i = 0;i < g1;i++){
- m6[ i ] = m5 % 10;
- m5 /= 10;
- }
- for (i = 0;i < g1;i++){
- m3 = pow (m6[i],g1);
- m4 = m3 + m4;
- }
- if (m1 == m4){
- cout << m1 << " ";
- m7++;
- }
- n2 += 1;
- }
- if (m7 == 0)
- cout << "none";
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment