C Program To Check An Array Is Armstrong Or Not

/*C Program to check given number is ARMSTRONG or not */
#include<stdio.h>
int main()
{
    int num,r,temp;
    int sum=0;
    printf("Enter any number to check Armstrong:");
    scanf("%d",&num);
    temp=num;
    while(num!=0)
    {
        r=num%10;
        num=num/10;
        sum=sum+(r*r*r);
    }
    if(sum==temp)
        printf("%d is an Armstrong number",temp);
    else
        printf("%d is not an Armstrong number",temp);
    return 0;
}

Output:

Enter any number to check Armstrong: 153
153 is an Armstrong number
Sharing Is Caring

Leave a Comment