C program to check the number is Armstrong Number or not

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
main()
{
 int num,result=0,n,rem;

//Accepting 3 digit number
 printf("Enter three digit number\n");
 scanf("%d",&num);
 n=num;

//Checking Armstrong or Not
 while(n!=0)
 {
  rem=n%10;
  result=result+rem*rem*rem;
  n=n/10;
 }
 if(result==num)
  printf("%d is an Armstrong Number",num);
 else
  printf("%d is not Armstrong Number",num);
}

OUTPUT:

Enter three digit number
153
153 is an Armstrong Number

Enter three digit number
145
145 is not Armstrong Number

Leave a Reply

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

9 + two =