C++ program to check whether the number is Armstrong or not, let’s understand what is Armstrong number.
Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.
Program for Armstrong Number in C++
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n,m=0,p=0,x,y;
cout<<"Enter any number: ";
cin>>n;
y=n;
while(y!=0){
y=y/10;
p++;
}
y=n;
while(n!=0)
{
x=n%10;
m+=pow(x,p);
n=n/10;
}
if(y==m)
cout<<"The given number is an armstrong number";
else
cout<<"The given number is not an armstrong number";
return 0;
}
Output of Program
Enter any number: 5
The given number is an armstrong number