Monday, November 4, 2013

Check the Given Number is Amstrong or Not

Check the Given Number is Amstrong or Not

Program:

#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("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: