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 whether a number is Armstrong number or not is as follows:

#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 convert binary number to octal number.
  2. Program to convert binary number to decimal number.
  3. Program to convert binary number to hexadecimal number.
  4. Program to convert octal number to binary number.
  5. Program to convert octal number to decimal number.
  6. Program to convert octal number to hexadecimal number.
  7. Program to convert decimal number to binary number.
  8. Program to convert decimal number to octal number.
  9. Program to convert decimal number to hexadecimal number.
  10. Program to convert hexadecimal number to binary number.
  11. Program to convert hexadecimal number to octal number.
  12. Program to convert hexadecimal number to decimal number.
  13. Program to check Leap Year.
  14. Program to Reverse a Number.
  15. Program to swap two Numbers.
  16. Program to print Fibonacci Series up to Nth Term.
  17. Program to find and print nth Fibonacci number.
  18. Program to find Power of the Number.
  19. Program to find Quotient and Remainder.
  20. Program to find largest amongst three numbers.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *