Checking Armstrong number using C++
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int x,num,y=0;
cout<<"Enter a number";
cin>>x;
num = x;
while(x!=0)
{
int a=x%10;
int d=a*a*a;
y=y+d;
x=x/10;
}
if(num==y)
cout<<"Armstrong number";
else
cout<<"Not Armstrong number";
return 0;
}
Comments
Post a Comment