C Program Find Armstrong Number

By | March 7, 2020

What is an Armstrong Number?

An Armstrong number is a n -digit number that is equal to the sum of each of its digits taken to the n th power.

Example of an Armstrong Number when number of digits=3

For example, 153 is an armstrong number because 153 = 1³ + 5³ + 3³.

1³ = 1

5³ = 125

3³ = 27

and 1+125+27 is equal to 153, therefore, 153 is an Armstrong Number.

C Source Code for Find or Check Armstrong Number (3 digits)

#include<stdio.h>  
 int main()    
{    
int n,rem,sum=0,temp;    
printf("Please enter a three digit number=");    
scanf("%d",&n);    
temp=n;    
while(n>0)    
{    
rem=n%10;    
sum=sum+(rem*rem*rem);    
n=n/10;    
}    
if(temp==sum)    
printf("%d is an armstrong  number ", temp);    
else    
printf("%d is not an not armstrong number", temp);    
return 0;  
}   

Output 1:

Please enter a three digit number=153
153 is an armstrong number

Output 2

Please enter a three digit number=371
371 is an armstrong number

Output 3

Please enter a three digit number=515
515 is not an not armstrong number

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *