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++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int n, rev = 0, num, r;

    cout << "\nEnter a Number :";
    cin>>n;

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

    if (rev == num) {
        cout << "\nNumber is ArmStrong :" << num;
    } else {
        cout << "\nNumber is Not ArmStrong :" << num;
    }

    return 0;
}

Output:

Enter a Number :153
Number is ArmStrong :153