Programming Examples

Cpp program to check given number is Armstrong or not


Write a C++ program to input any number and check number is Armstrong  or Not.

Solution

#include <iostream>
using namespace std;
int main()
{
   int num, temp, rem, arm=0;
    cout<<"Enter a number: ";
    cin>>num;
    temp = num;
    while(num>0)
    {
        rem = num%10;
        arm = arm + (rem*rem*rem);
        num = num/10;
    }
    if(temp==arm)
    cout<<"It is an Armstrong number";
   else
    cout<<"It is not an Armstrong number";
    return 0;
}
Output

Enter a number: 23

It is not an Armstrong number

----------------------------------------------------

Enter a number: 153

It is an Armstrong number

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz