Saturday, December 9, 2017

UVa problem solution 12895 - Armstrong Number

problem link:

Discuss: in this problem you just have to easily find out the number of digit then power every digit with the number of digit and sum it. it will okay to use while loop as well as use string and for loop.

N.B. some output in Udebug is not match to the accepted output.

try  yourself before see the code



#include<bits/stdc++.h>
using namespace std;
int main()
{

    int t;
    cin >>t;
    while(t--)
    {
        long long n,i,j,cnt=0,flag=0,c1=0,m,s,d=0,pd;
        cin >>n;
      m=n;
      while(n>0)
      {
          n/=10;
          d++;
      }
      n=m;
      while(n>0)
      {
          pd=n%10;
          m-=pow(pd,d);
          n/=10;
      }
        if(m==0)
            cout <<"Armstrong"<<endl;
        else
            cout <<"Not Armstrong"<<endl;
    }
    return 0;
}

No comments:

Post a Comment