Tuesday, 17 March 2015

Armstrong Number

//Armstrong Number : When Sum of Cubes of Digits Of Number Equal to Same Given Number then the number is called as Armstrong Number.


#include<stdio.h>

int main() {
   int num, temp, sum = 0, rem;

   printf("\nEnter number for checking Armstrong : ");
   scanf("%d", &num);

   temp = num;

   while (num != 0) {
      rem = num % 10;
      sum = sum + (rem * rem * rem);
      num = num / 10;
   }

   if (temp == sum)
      printf("%d is Amstrong Number", temp);
   else
      printf("%d is Amstrong Number", temp);

   return (0);
}

Output :
Enter Number For Checking Armstrong : 153
153 is Amstrong Number

Explanation :
153 = [1*1*1] + [5*5*5] + [3*3*3]
    = 1 + 125 + 27
    = 153

No comments:

Post a Comment