How to do it…

  1. Enter a number to assign to the n variable:
printf("Enter a number ");
scanf("%d",&n);
  1. Invoke the findarmstrong function. The value assigned to n will get passed to this function:
findarmstrong(n)
  1. In the function, the passed argument, n, is assigned to the numb parameter. Execute a while loop to separate out all the digits in the numb parameter:
while(numb >0)
  1. In the while loop, apply the mod 10 (%10) operator on the number assigned to the numb variable. The mod operator divides a number and returns the remainder:
remainder=numb%10;
  1. Push the remainder to the stack:
push(remainder);
  1. Remove the last digit of the number in the numb variable by dividing the numb variable by 10:
numb=numb/10;
  1. Repeat steps 4 to 6 until the number in the numb variable becomes 0. In addition, create a count counter to count the number of digits in the number. Initialize the counter to 0 and it will get incremented during the while loop:
count++;
  1. Pop all the digits from the stack and raise it to the given power. To pop all the digits from the stack, execute a while loop that will execute until top is greater than or equal to 0, that is, until the stack is empty:
while(top >=0)

  1. Inside the while loop, pop off a digit from the stack and raise it to the power of count, which is the count of the number of digits in the selected number. Then, add all the digits to the value:
j=pop();
value=value+pow(j,count);
  1. Compare the number in the value variable with the number in the numb variable, and code it to return the value of 1 if both the compared numbers match:
if(value==numb)return 1;

If the numbers in the numb and value variables are the same, returning the Boolean value of 1, that means the number is an Armstrong number. 

Here is the armstrong.c program for finding out whether the specified number is an Armstrong number:

/* Finding whether the entered number is an Armstrong number */
# include <stdio.h>
# include <math.h>

#define max 10

int top=-1;
int stack[max];
void push(int);
int pop();
int findarmstrong(int );
void main()
{
int n;
printf("Enter a number ");
scanf("%d",&n);
if (findarmstrong(n))
printf("%d is an armstrong number",n);
else printf("%d is not an armstrong number", n);
}
int findarmstrong(int numb)
{
int j, remainder, temp,count,value;
temp=numb;
count=0;
while(numb >0)
{
remainder=numb%10;
push(remainder);
count++;
numb=numb/10;
}
numb=temp;
value=0;
while(top >=0)
{
j=pop();
value=value+pow(j,count);
}
if(value==numb)return 1;
else return 0;
}
void push(int m)
{
top++;
stack[top]=m;
}
int pop()
{
int j;
if(top==-1)return(top);
else
{
j=stack[top];
top--;
return(j);
}
}

Now, let's go behind the scenes.