/* Armstrong Number: A positive number is called armstrong number if it is equal to the sum of cubes of its digits for example 0, 1, 153, 370, 371, 407 etc.
Let's try to understand why 153 is an Armstrong number.
153 = (1*1*1)+(5*5*5)+(3*3*3)where:
(1*1*1)=1
(5*5*5)=125
(3*3*3)=27
So:
1+125+27=153
*/
#include<iostream>
using namespace std;
int main()
{
int n,n1,d,cube,sum=0;
cout<<"Enter a Number\n";
cin>>n;
n1=n;
while(n>0)
{
d=n%10;
cube=d*d*d;
sum=sum+cube;
n=n/10;
}
if(sum==n1)
cout<<n1<<" is an Armstrong Number";
else
cout<<n1<<" is not an Armstrong Number";
}
No comments:
Post a Comment