ArmStrong Number


#include <stdio.h>

void armstrong(void);
int main (int argc, const char * argv[])
{
    armstrong();  
    return 0;
}
void armstrong(void)
{
    int remainder,sum,n;
  
    for (int i=1; i<500; i++)
    {
        sum = 0;
        n=i;
      
        while (n>0)
        {
            remainder = n%10;
            sum += remainder*remainder*remainder;
            n  = n/10;
        }
        if (sum==i)
        {
            printf("\n%d",i);
        }
    }
  
  
}

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comments:

Post a Comment