Armstrong Number

Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. Example: 153 = 1^3 + 5^3 + 3^3. 


#include<stdio.h>
void main()
{
 int num,num1,arms=0,rem;

 printf("Enter the number:\n");
 scanf("%d",&num);
 num1=num;
 while(num>0)
 {
  rem=num%10;
  arms=arms+rem*rem*rem;
  num=num/10;
 }
 if(num1==arms)
 {
  printf(" \n%d is an Armstrong number",num1);
 }
 else
 {
  printf("\n%d is NOT an Armstrong number",num1);
 }

} 

Post a Comment

Previous Post Next Post