C Program to check whether number is Armstrong number or not

#include<stdio.h>
#include<math.h>
main()
{
  int num,i,j,temp,sum=0;;
  printf("Enter a number to know whether it is armstrong or not\n");
  scanf("%d",&num);
  temp=num;
  while(num>0)
  {
    i=num%10;
    sum+=i*i*i;
    num=num/10;
  }
  if(sum==temp)
  {
    printf("Giveb number %d is an armstrong number\n",temp);
  }
  else
  {
    printf("Giveb number %d is not an armstrong number since
         the sum of cubes of individual digits is %d\n",temp,sum);
  }
}
Output:

Enter a number to know whether it is armstrong or not
371
Giveb number 371 is an armstrong number

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post