A number in which the sum of cube of its individual digits is equal to the number itself is called Armstrong numberFor Example: 1^3 + 5^3 + 3^3 = 153
4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407 is an Armstrong number.
C++ program which takes input a number and check whether it is Armstrong Number or not.
C++ program to check whether number is armstrong or not
#include<iostream.h>
using namespace std;
int main()
{
int armstrong=0,num=0,result=0,check;
cout<<"Enter Number to find it is an Armstrong number ";
cin>>num;
check=num;
for(int i=1;num!=0;i++){
armstrong=num%10;
num=num/10;
armstrong=armstrong*armstrong*armstrong;
result=result+armstrong;
}
if(result==check){
cout<<check<<" is an Armstrong Number";
}
else{
cout<<check<<" is NOT an Armstrong Number";
}
return 0;
}
using namespace std;
int main()
{
int armstrong=0,num=0,result=0,check;
cout<<"Enter Number to find it is an Armstrong number ";
cin>>num;
check=num;
for(int i=1;num!=0;i++){
armstrong=num%10;
num=num/10;
armstrong=armstrong*armstrong*armstrong;
result=result+armstrong;
}
if(result==check){
cout<<check<<" is an Armstrong Number";
}
else{
cout<<check<<" is NOT an Armstrong Number";
}
return 0;
}
Output
Enter Number to find it is an Armstrong number 153
153 is an Armstrong Number