Thursday, 21 August 2014

Armstrong program in C


Armstrong Number : When Sum of Cubes of Digits Of Number Equal to Same Given Number then the number is called as Armstrong Number.For example 153 is an  Armstrong number .
Explanation is given below
153  [1*1*1] + [5*5*5] + [3*3*3]
        =  1 + 125 + 27
        =  153

C program for finding 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.