C program to find whether the given number is Armstrong or not : (e.g: 153= 1ᶾ + 5ᶾ + 3ᶾ = 153 )

#include< stdio.h >
#include< conio.h >
void main()
{
          int sum=0,digit,n,temp;
         clrscr();
         printf("Enter a number:");
         scanf("%d",&n);
         temp=n;
         while(n!=0)
         {
                digit=n%10;
                sum=sum+digit*digit*digit;
                n=n/10;
         }
         if(sum==temp)
        {
                printf("The number %d is an Armstrong Number",n);
        }
        else
        {
               printf("The number %d is not an Armstrong Number",n);
        }
        getch();
}

OUTPUT :

Enter a number :153
The number 153 is an Armstrong Number

OR

OUTPUT :

Enter a number :152
The number 152 is not an Armstrong Number

No comments :

Post a Comment