Home >>c programs >Armstrong Number Program in C

Armstrong Number Program in C

Armstrong Number Program in C

An Armstrong number is a number which equal to the sum of the cube to the number itself.

An Armstrong number is always in a three-digit number.

For Example:-

370 = (3)3  + (7)3  +(0)3 
370 = 27 + 343 + 0
370 = 370

OR

153 = (1)3 + (5)3 + (3)3
153 = 1 + 125 + 27
153 = 153

Let's take an example of Armstrong Number:

#include<stdio.h>  
int main()    
{    
int num,rem,sum=0,temp;    
printf("Enter Your  number to check armstrong ");    
scanf("%d",&num);    
temp=num;    
while(num>0)    
{    
rem=num%10;    
sum=sum+(rem*rem*rem);    
num=num/10;    
}    
if(temp==sum)
{    
printf("Given Number is armstrong");    
}
else
{    
printf("Given Number is not armstrong");    
}
return 0;  
}   
Output :
Enter Your number to check armstrong 153
Given Number is armstrong
Output :
Enter Your number to check armstrong 123
Given Number is not armstrong

Popular Tutorials