I am finding Armstrong number but it's showing "not a Armstrong number" Everytime and I can't find the solution. as my observation I think there is some problem the sum section. the sum is not giving the correct value.
#include<stdio.h>
#include<math.h>
int main()
{
int num, original_num, sum=0, lastdigit, digit, count=1;
printf("Enter the number: ");
scanf("%d", &num);
original_num = num;
while (num >= 10)
{
count++;
num /= 10;
}
digit = count;
while (num > 0)
{
lastdigit = num % 10;
sum += pow(lastdigit, digit); /** here is the problem lying as my
observation, the sum is giving the
incorrect value.**/
num/=10;
}
if (original_num == sum)
{
printf("The number is an ARMSTRONG number");
}
else
{
printf("The number is not a ARMSTRONG number");
}
return 0;
}