Home >>Cpp Programs >Armstrong Number in C++
In order to proceed to learn the program of the Armstrong number in C++ programming language, it is mandatory to understand that what the Armstrong number is.
Well, Armstrong Number is any number that is generally the resultant of the cubes of its own digits. In simple words, suppose a number is 407, if we have to prove that it is an Armstrong number then, we have to calculate the sum of the cubes of its digits like: (4)3 + (0)3 + (7)3 and the result will be = 64 + 0 + 343 = 407. The resultant is same as the number taken; hence it can be called as an Armstrong Number.
153,370,407, 1634 etc these numbers are Armstrong numbers.
Let's take another number for a better understanding of the Armstrong numbers: 370
370 = (3*3*3) + (7*7*7) + (0*0*0) Where: (3*3*3) = 27 (7*7*7) = 343 (0*0*0) = 0 Hence: 27 + 343 + 0 = 370
Here is the program that is used in the C++ programming language to check whether a number that has been entered by the user is an Armstrong number or not. This example will help you in understanding the topic from a deeper level for a better understanding:
#include <iostream> using namespace std; int main() { int num,rem,sum=0,temp; cout<<"Please Enter Your Number : "; cin>>num; temp=num; while(num>0) { rem=num%10; sum=sum+(rem*rem*rem); num=num/10; } if(temp==sum) { cout<<"Given number is Armstrong number."<<endl; } else { cout<<"Given number is Not Armstrong number."<<endl; } return 0; }