#include <iostream> #include <math.h> using namespace std; // for find how many values for root; int div(int a){ int n=0; while (a!=0) { int d=a%10; a/=10; n++; } return n; } //for sum of the digit int sum(int a){ int sum=0; int n=a; while (a!=0) { int d=a%10; sum+=pow(d,div(n)); a/=10; } return sum; } //main function int main(){ int a; cin>>a; int n=a; if(sum(a)==n){ cout<<"Armstrong number"; } else{ cout<<"Not a Armstrong number"; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter