Check Armstrong Number

Check Armstrong Number” is again basic programming exercise problem for beginners. Here, we are given a number entered by user and our task is to write a program to check whether entered number is an Armstrong number or not.

A number is said to be Armstrong number when sum of cubes of each digit of the number equals to number itself.

For example, 153 = 1*1*1 + 5*5*5 + 3*3*3 = 1 + 125 + 27 = 153

C++ Program to check Armstrong number is as follows:

/* C++ Program to Check Armstrong Number */
#include<bits/stdc++.h>  
using namespace std;  
int main()  
{  
    //Scan the number  
    int num;  
    cout<<"Enter the number:";  
    cin>>num;  
      
    //Check Armstrong number  
    int temp_num = num;  
    int check = 0;  
    while(temp_num > 0)  
    {  
        int digit = temp_num % 10;  
        check = check + (digit * digit * digit);  
        temp_num = temp_num / 10;  
    }  
    if(check == num)  
    cout<<num<<" is an Armstrong Number";  
    else  
    cout<<num<<" is not an Armstrong Number";  
}  

OUTPUT:
Enter the number:153
153 is an Armstrong Number

Related Posts:

  1. Program to find GCD of two numbers.
  2. Program to find LCM of two numbers.
  3. Program to check whether entered number is odd or even.
  4. Program to check whether entered number is prime number or not.
  5. Program to check whether entered number is palindrome or not.
  6. Program to convert binary number to octal number.
  7. Program to convert binary number to decimal number.
  8. Program to convert binary number to hexadecimal number.
  9. Program to convert octal number to binary number.
  10. Program to convert octal number to decimal number.
  11. Program to convert octal number to hexadecimal number.
  12. Program to convert decimal number to binary number.
  13. Program to convert decimal number to octal number.
  14. Program to convert decimal number to hexadecimal number.
  15. Program to convert hexadecimal number to binary number.
  16. Program to convert hexadecimal number to octal number.
  17. Program to convert hexadecimal number to decimal number.
  18. Program to check Leap Year.
  19. Program to find sum of first ‘n’ natural numbers.
  20. Program to Reverse a Number.

You may also like...