Armstrong number check

adroit89's Avatar author of Armstrong number check
This is an article on Armstrong number check in C.
To check whether entered number is armstrong number or not.
Code: C
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
    int n,sum=0,rem=0,cube=0,n1,i;
    clrscr();
    printf("enter a number");
    scanf("%d",&n);
    n1=n;
    while(n!=0)
    {
        rem=n%10;
        cube=pow(rem,3);
        sum=sum+cube;
        n=n/10;
    }
    if(sum==n1)
        printf("angstrom");
    else
        printf("not angstrom");
    getch();
}
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You are printing the wrong output.
Code:
    if(sum==n1)
        printf("angstrom");
    else
        printf("not angstrom");
It should be armstrong number and not angstrom. For those who dont know what it is.

Armstrong number: An n-digit number equal to the sum of the nth powers of its digits.
There are no two-digit Armstrong numbers; and there are four three-digit Armstrong numbers: 153, 370, 371, and 407.
1x1x1 + 5x5x5 + 3x3x3 = 153
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
I have read the above program and try to understand it but i cannot understand all. I only can calculate the 53 without the 1 and 370 without the 3. I don't know why. Your explanations is greatly appreciated by me and others.

n=n/10; -- Is it the 153 calculate 3 first, then 5 and finally 1.


Sorry for my stupidness.

Your help is greatly appreciated by me an others.
Peter_APIIT's Avatar, Join Date: Apr 2007
Contributor
Thanks for your help.