C++ program for Armstrong Number

In this article, you will learn a C++ program for Armstrong Number. In this C++ program, the user is asked to enter any number the program tells whether it’s an Armstrong number or not.

Armstrong numbers are those numbers that are equal to the sum of cubes of their digits.

Armstrong number in cpp

Example 1: Check Armstrong Number in C++

#include <iostream>
using namespace std;
 
int main()    
{    
int num,r,sum=0,temp;    
cout<<"Enter any number: ";    
cin>>num;   
temp=num;    
while(num>0)    
{    
r=num%10;    
sum=sum+(r*r*r);    
num=num/10;    
}    
if(temp==sum)    
cout<<temp<<" is an armstrong  number ";    
else    
cout<<temp<<" is not an armstrong  number ";    
return 0;  
}

Output

Enter any number: 153
153 is an armstrong  number

Scroll to Top