You are given an integer 'n'.
Return 'true' if 'n' is an Armstrong number, and 'false' otherwise.
You are given an integer 'n'.
Return 'true' if 'n' is an Armstrong number, and 'false' otherwise.
An Armstrong number is a number (with 'k' digits) such that the sum of its digits raised to 'kth' power is equal to the number itself.
For example, 371 is an Armstrong number because 3^3 + 7^3 + 1^3 = 371.
bool checkArmstrong(int n){//Write your code hereint num=0,temp;int count=0;for(int i=n;i>0;i=i/10)count++;for(int i=n;i>0;i=i/10){temp=i%10;num=num+pow(temp,count);}if(num==n)return true;elsereturn false;}
Comments
Post a Comment