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