#include
#include
main()
{
int temp,rem,sum=0,n;
clrscr();
printf("Enter n : ");
scanf("%d", &n);
temp=n;
while(n > 0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(temp==sum)
printf("Armstrong Number");
else
printf("Not an Armstrong Number");
getch();
}
Here is the extended version of the program.. to check Armstrong number conditions for the number of any given length
int getMultiplication(int rem, int intLength)
{
int sum = 1;
for (int i = 1; i< = intLength; i++) { sum *= rem; } return sum; } int findLength(int n) { int count=0; while(n > 0)
{
count = count + 1;
n=n/10;
}
return count;
}
void main()
{
int temp,rem,sum=0,n, intLength;
printf("Enter n : ");
scanf("%d", &n);
temp=n;
intLength = findLength(n);
printf(" intLength= %d ",intLength);
while(n > 0)
{
rem=n%10;
sum = sum+ getMultiplication(rem, intLength );
n=n/10;
}
if(temp==sum)
printf("Armstrong Number");
else
printf("Not an Armstrong Number");
}