Armstrong Number in C++

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Basic C++ Program, we will have a look at how to write a c++ program to write a c++ program to check Armstrong number.

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

C++ program to check Armstrong Number.

#include <iostream>  

using namespace std;  

int main()  

{  

int n,sum=0,m;    

cout<<"Please enter a number: ";    

cin>>n;    

while(n>0)    

{    

m=n%10;    

sum=sum+m;    

n=n/10;    

}    

cout<<"Sum is= "<<sum<<endl;    

return 0;  

Output:

Please enter a number: 24

Sum is= 6

Leave a Comment

Your email address will not be published. Required fields are marked *