Monday, June 18, 2012

To check whether the given number is an Armstrong number


/* To check whether the given number is an Armstrong number */
/* A number is an Armstrong number if sum of the cube of its digits is equal to the number */
#include<stdio.h>
#include<conio.h>
void main()
{
  int num,d,temp,sum=0;
  clrscr();
  printf("Enter the number: ");
  scanf("%d",&num);
  temp=num;
  while(num!=0)
  {
    d=num%10;
    num=num/10;
    sum=sum+(d*d*d);
  }
  if(sum==temp)
    printf("%d is an Armstrong Number!",temp);
  else
    printf("%d is NOT an Armstrong Number!",temp);
  getch();
}
 
OUTPUT
Enter the number: 153
153 is an Armstrong Number!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.