A number is Armstrong number only if the sum of cubes of every individual digits of that number is equal to the number itself. For example 153 is an Armstrong number as 13 + 53 + 33 = 153. Some other Armstrong numbers are: 0, 1, 153, 370, 407. But 123 is not a Armstrong number as 13 + 23 + 33 = 36.
Let’s write the program
Let’s write the program
#include<iostream>
using namespace std;
main()
{ int i=0,n,m,k;
cout<<"Enter Your Number";
cin>>n;
m=n;
while(n!=0)
{ k=(n%10);
i=i+k*k*k;
n=n/10;
}
if(i==m)
{ cout<<"This number is Armstrong";
}
else
{ cout<<"This number is Not Armstrong";
}
}
The output of above program isusing namespace std;
main()
{ int i=0,n,m,k;
cout<<"Enter Your Number";
cin>>n;
m=n;
while(n!=0)
{ k=(n%10);
i=i+k*k*k;
n=n/10;
}
if(i==m)
{ cout<<"This number is Armstrong";
}
else
{ cout<<"This number is Not Armstrong";
}
}
Enter Your Number 153
This number is Armstrong
Enter Your Number 123
This number is Not Armstrong
This number is Armstrong
Enter Your Number 123
This number is Not Armstrong

0 comments:
Post a Comment