Finding whether a number is an Armstrong number in C

Last Updated On Wednesday 25th Aug 2021

An Armstrong number is a three-digit integer that is the sum of the cubes of its digits.
This simply means that if xyz = x3+y3+z3
, it is an Armstrong number.For example, 153
is an Armstrong number because 13+53+33= 153

	// 370 = (3*3*3)+(7*7*7)+(0) = 27+343+0=370
	
	#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 num) {
    int j, remainder, temp, count, value;
    temp = num;
    count = 0;
    while (num > 0) {
        remainder = num % 10;
        push(remainder);
        count++;
        num = num / 10;
    }
    num = temp;
    value = 0;
    while (top >= 0) {
        j = pop();
        value = value + pow(j, count);
    }
    if (value == num) 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);
    }
}
	
	// Enter a number 370
// 370 is an armstrong number
	

References

While Loop