C – ArmStrong Number

C Program to check the 3 digits number is Armstrong number or not:

Example:        153  à 1^3 + 5^3 + 3^3 = 153

int main()
{
            int n, r, sum=0, temp;
            printf(“Enter num : “);
            scanf(“%d”, &n);
            temp=n;
            while(n>0){
                        r = n%10;
                        sum = sum + r*r*r;
                        n = n/10;
            }
            if(temp==sum)
                        printf(“Armstrong number \n”);
            else
                        printf(“Not an Armstrong number \n”);
            return 0;
}

C Program to check the given number is Armstrong number or not:

  • 2-digit number: Sum of squares of individual digits equals to the same number
  • 3-digit number: Sum of cubes of individual digits equals to the same number
  • 4-digit number: Sum of individual digits power 4 equals to the same number
    • 153 = 1^3 + 5^3 + 3^3 = 153
    • 1634 = 1^4 + 6^4 + 3^4 + 4^4 = 1634
int main()
{
            int n, r, sum=0, temp, c=0, s, i;
            printf(“Enter num : “);
            scanf(“%d”, &n);
            temp=n;
            while(n>0){
                        n=n/10;          
                        c++;
            }
            n=temp;
            while(n>0){
                        r = n%10;
                        s=1;
                        for(i=1 ; i<=c ; i++)
                                    s = s*r;
                        sum = sum + s;
                        n = n/10;
            }
            if(temp==sum)
                        printf(“Armstrong number \n”);
            else
                        printf(“Not an Armstrong number \n”);
}
Scroll to Top