About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Monday, September 2, 2013

Programs : Check for Armstrong Number 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.
#include<stdio.h>
int main()
{
int num,temp,sum=0,rem;

printf("Enter 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("n%d is Amstrong Number",temp);
else
    printf("n%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: