Three digit number is armstrong number or not

C program to determine whether a 3 digit number entered by user is an Armstrong number or not.

An armstrong number of a 3 digit number is a number in which the sum of the cube of the digits is equal to the number itself.

Example:
153 is an armstrong number.

1*1*1 + 5*5*5 + 3*3*3
1 + 125 + 27
153
Hence, 153 is an armstrong number.

Other Armstrong numbers are: 370, 371, 407


Program

#include<stdio.h>
#include<conio.h>
void main()
{
	int number,o,t,h;

    printf("\nEnter a three digit number\t: ");
    scanf("%d",&number);

    o=number%10;
    h=number/100;
    t=(number/10)%10;
    //printf("\nOnes place\t:%d\nTens place\t:%d\nHundreds place\t:%d",o,t,h);

    if(number==(o*o*o)+(t*t*t)+(h*h*h))
    {
        printf("\nIts an armstrong number");
    }
    else
    {
        printf("\nIt is not an armstrong number");
    }

    getch();
}

Output

********** Run1 **********

Enter a three digit number      : 153

Its an armstrong number


********** Run2 **********

Enter a three digit number      : 234

It is not an armstrong number

Explanation

To check whether a number is an armstrong number or not, first we have to extract the individual digits of the number. Then, we will check whether the sum of cubes of the digits is equal to the number itself or not. If equal, then it is an armstrong number. If not, then, it is not an armstrong number.

To extract the digits, following expressions are used:
o=number%10;
h=number/100;
t=(number/10)%10;
where, 'number' variable is used to store the value of the number entered by the user. ones, tens, and hundreds digits of the number are extracted and stored in 'o', 't' and 'h' variables respectively.

Next step is to calculate the sum of cubes of the digits and compare it with the actual number. Condition used is
number == (o*o*o) + (t*t*t) + (h*h*h)
If, above condition evaluates to true, then, the number is an armstrong number.
Else, the number is not an armstrong number.