ARMSTRONG NUMBER OR NOT

Consider the following I/O samples.




SAMPLE INPUT: 153

SAMPLE OUTPUT:  ARMSTRONG NUMBER

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.

407 = 4^3 + 0^3 + 7^3 = 407




C PROGRAM:

#include<stdio.h>
int main()
{
    int num,temp,ans=0,rem;
    scanf("%d",&num);
    temp=num;
    while(temp)
     {
        rem=temp%10;
        ans=ans+rem*rem*rem;
        temp=temp/10;
     }
     if(ans == num) 
        printf("Armstrong number");
    else
        printf("Not Armstrong number");
    return 0;
}



OUTPUT:

                    



The given source code in C program "FOR ARMSTRONG NUMBER OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.

Comments

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE