Introduction

Control Statement

- Program to print Fibonacci series
- Check Whether the Number is Even or Odd in C++
- Program to check whether the number is prime or not
- Program to check vowel or constant
- Program to check the largest number among three numbers
- Program to the sum of natural numbers
- Program to check leap year
- Program to find factorial of the number
- Program to find reverse of the number

Function

- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle

Array

Pointer

OOPS

No Examples found for this topic - CodeHelpPro

# Program to Check Armstrong Number

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

Login

0 Comments

Inline Feedbacks

View all comments