Program to Check Armstrong Number - C Program

Program to Check Armstrong Number

Armstrong number is a number that is equal to the sum of cubes of its digits for example 1, 153, 370, 371, 407 etc. For example 153 since 1^3 + 5^3 + 3^3 = 1+ 125 + 27 =>153

#include <stdio.h>
int main()
{
    int num,n, qsum=0,r;
    printf("Enter the number :");
    scanf("%d",&num);
    n = num;
    while(n!=0)
    {
         r=n%10;
         qsum =qsum+(r*r*r);
         n = n / 10;
    }
    if(qsum==num)
         printf("Number is Armstrong Number");
    else
         printf("Number is not a Armstrong Number");
    return 0;
}

Output - Program to Check Armstrong Number

Enter the number :153    
Number is Armstrong Number
Compile and Run Online