Program to Check Number Is Armstrong Number Or Not Using Function - C Program

Program to Check Number Is Armstrong Number Or Not Using Function

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 isArmstrong(int num);
int main()
{
    int num,result;
    printf("Enter the number:");
    scanf("%d",&num);
    result = isArmstrong(num);
    if(result==1)
        printf("%d is armstrong number",num);
    else
        printf("%d is not an armstrong number",num);
    return 0;
}
int isArmstrong(int num)
{
    int qsum=0,r,n;
    n=num;
    while(n>0)
    {
        r=n%10;
        qsum=qsum+(r*r*r);
        n=n/10;
    }
    if(qsum==num)
        return 1;
    else
        return 0;
}

Output - Program to Check Number Is Armstrong Number Or Not Using Function

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