KodeGod.com

031. Write a program to accept a number from user and check if it is Armstrong number or not i.e. 153 = 1^3 + 5^3 + 3^3 = 153 in C language

#include
#include
main()
{
  int temp,rem,sum=0,n;
  clrscr();
  printf("Enter n : ");
  scanf("%d", &n);
  temp=n;
  while(n > 0)
  {
	   rem=n%10;
	   sum=sum+rem*rem*rem;
	   n=n/10;
  }
  if(temp==sum)
		printf("Armstrong Number");
  else
		printf("Not an Armstrong Number");
  getch();
}