Armstrong Number in C

Armstrong number is a number which is equal to sum of digits raise to the power total number of digits in the number. For example, 371 is an Armstrong number since 3*3*3 + 7*7*7 + 1*1*1 = 371.

Source code :

#include <stdio.h>

int main()
{
   int sum = 0, t, r , num;
   
   printf("Enter a number : ");
   fflush(stdout);
   
   scanf("%d",&num);

   t = num;
   while( t != 0 )
   {
      r = t%10;
      sum = sum + r*r*r;
      t = t/10;
   }
   
   printf("\n");

   if ( num == sum )
      printf("%d is armstrong number",num);
   else
      printf("%d is an armstrong number",num);

   return 0;
}


Output :

Enter a number : 371
371 is armstrong number

Notes :

371 = 333 + 777 + 111
153 = 111 + 555 + 333
371 and 153 are Armstrong numbers


Output :


                

Comments :