Now what to do........,,,,,,

#include
#include
using namespace std;

int main()
{
int origNum, num, rem, sum = 0;
int count=0;
cin >> origNum;

num = origNum;

while(num != 0)
{
rem = num % 10;
sum += pow(rem,count);
num/= 10;
count++;
}

if(sum == origNum)
cout << " true";
else
cout << " false";

return 0;
}

Hey @neelrai906
The flow goes like this:
First of all, you calculate the no. of digits in a number, using a while loop.
Then you add pow(dig, no_of_dig) for each digit and add, using another while loop.

You’ve added and counted in same while loop which will result in wrong ans.
for example for 371:

  1. you calculate count(no of digits) using first while loop which comes out to be 3,
  2. then you calculate 3^3+7^3+1^3 using another while loop, which gives 371, then you get to the result that it is an Armstrong number.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.