#include<stdio.h>
#include<math.h>
int main()
{
int n, num, sum=0, count=0, a, remain=0;
printf("Enter a number : ");
scanf("%d", &num);
a=num;
n=num;
while(a!=0)
{
a=a/10;
count++;
}
while(n!=0)
{
remain=n%10;
sum=sum+pow(remain, count);
printf("%d\n", sum);
n=n/10;
}
if(sum==num)
printf("Armstrong Number");
else
printf("Not an Armstrong Number");
return 0;
}
guys I am trying to make a program of checking if a number is Armstrong number or not. And I am facing this problem with '153' as an input specifically. The program works fine with various inputs but compiler is showing unusual behavior while adding 153. I will also attach the output with different inputs explicitly showing the addition of numbers in the 'sum' variable.
OUTPUT:
Enter a number : 153
27
151
152
Not an Armstrong Number
Enter a number : 371
1
344
371
Armstrong Number