This is a C++ Program to Check if a Number is an Armstrong Number.

The program takes a number and checks if it is an Armstrong number. An n-digit number such that the sum of each digit raised to the power n is the number itself, is an Armstrong number.

1. The number to be checked is entered.

2. Each digit is cubed, and added.

3. If the eventual sum of the cubed digits is equal to the number entered, then it is an Armstrong number.

4. Else it is not.

5. The result is printed.

6. Exit.

Here is the source code of C++ Program to Check if a Number is an Armstrong Number. The program output is shown below.

`#include<iostream>`

using namespace std;

int main ()

`{`

int num, temp, rem, sum = 0;

cout << "Enter number to be checked : ";

cin >> num;

temp = num;

while (temp != 0)

`{`

rem = temp % 10;

sum = sum + rem*rem*rem;

temp = temp / 10;

`}`

if (sum == num)

cout << "\n" << num << " is an Armstrong number.";

`else`

cout << "\n" << num << " is not an Armstrong number.";

return 0;

`}`

1. The user is asked to enter the number to be checked and it is stored in the variable ‘num’.

2. The variable sum is initialized as 0.

3. The value of num is assigned to a temporary variable temp and it is checked.

4. Each digit is cubed and added to the variable sum using a while loop and modulus operator.

5. If the value of sum is equal to the value of the number entered, i.e num, then it is an Armstrong number.

6. Else the entered number is not an Armstrong number.

7. The result is then printed.

Case 1 : Enter number to be checked : 371 371 is an Armstrong number. Case 2 : Enter number to be checked : 18 18 is not an Armstrong number. Case 3 : Enter number to be checked : 153 153 is an Armstrong number.

**Sanfoundry Global Education & Learning Series – C++ Programs.**

To practice all C++ programs, __here is complete set of 1000+ C++ Programming examples__.