Armstrong Number in C


Armstrong Number in C

Below I shared C program to check Armstrong Number in C. So, An Armstrong Number is sum of n of each individual digits is equal
to the number itself  For example, if user enter the number 153 then output will be:

#include<stdio.h>
#include<math.h>
int main()
{ int num,orig,a,result=0,n=0;
 printf("\n\tEnter a number :-");
 scanf("%d",&num);
 orig=num;
 while(orig!=0)
 {
  orig=orig/10;
  n++;
 }
 orig=num;
 while(orig!=0)
 {
  a=orig%10;
  result=result+pow(a,n);
  orig=orig/10;
 }
 if(result==num)
 {
  printf("\nThe number %d is armstrong",num);
 }
 else
 {
  printf("\nThe number %d is not armstrong",num); 
 }
return 0;
} 


NOTE: You have any problem in above C program to check armstrong number in C do not hesitate and write your problem in the comment box. I will support your problem.

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form