Armstrong Number For N Digits

in Hindi - Armstrong Number For N Digits



not yet

Source Code :

RUN#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int num1, num2, base, power = 0, ans = 0;

cout<<"Enter Number : "<<endl;
cin>>num1;

num2 = num1;
while (num2 != 0)
{
power += 1;
num2 = num2 / 10;
}
num2 = num1;
while( num2 > 0)
{
base = num2 %10;
ans = ans + pow(base, power);
num2 = num2 /10;
}

if (ans == num1){
cout<<num1<<" is an Armstrong Number.";
}else{
cout<<num1<<" is not an Armstrong Number.";
}
return 0;
}