C++ Program to check number is Armstrong or not


In this program, You will learn how to check number is Armstrong or not in C++.


Some list of Armstrong number is : 153, 370, 371

Example: How to check number is Armstrong or not in C++.

#include<iostream>
using namespace std;

int main() {

    int n, rev = 0, num, r;

    cout << "Enter a number:";
    cin>>n;

    num = n;
    while (n > 0) {
        r = n % 10;
        rev = rev + r * r * r;
        n = n / 10;
    }

    if (rev == num) {
        cout << "Number is ArmStrong:" << num;
    } else {
        cout << "Number is not ArmStrong:" << num;
    }

    return 0;
}

Output:

Enter a number:153
Number is ArmStrong:153