code to check whether a no is Armstrong no or not



#include<stdio.h>
int main(){
    int num,r,sum=0,temp;

    printf("Enter a number: ");
    scanf("%d",&num);

    temp=num;
    while(num!=0){
         r=num%10;
         num=num/10;
         sum=sum+(r*r*r);
    }
    if(sum==temp)
         printf("%d  It is an Armstrong number",temp);
    else
         printf("%d It is not an Armstrong number",temp);
    return 0;
}

Output:-

Enter a number: 153
It is an Armstrong number

0 comments :