Program to Check Armstrong Number

0 Suresh Chand March 28, 2021

In this example, we will learn how to check whether number is Armstrong or not.

To understand this example, We must have knowledge on following topics

Armstrong number is the number that is equal to sum of cubes of each digits. For example, 0, 1, 153 are amrstrong number.

Let’s check whether 153 is Armstrong ot not

153 = 1^3 + 5^3 + 3^3 = 153

Let’s look an code

#include <iostream>
using namespace std;

int main() {
    int num, originalNumber, remainder, result = 0;
    cout << "Enter a three-digit integer: ";
    cin >> num;
    originalNumber = num;

    while (originalNumber != 0) {
        // remainder that contains the last digit
        remainder = originalNumber % 10;
        
        result += remainder * remainder * remainder;
        
        // removing last digit from the orignal number
        originalNumber /= 10;
    }

    if (result == num)
        cout << num << " is an Armstrong number.";
    else
        cout << num << " is not an Armstrong number.";

    return 0;
}

The output of above program is

Enter a three-digit integer: 153
153 is an Armstrong number.

Enter a three-digit integer: 32
32 is not an Armstrong number.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by codehelppro.com

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System