Write C program to check whether a input number is Armstrong number or not.

#include<conio.h>
#include<stdio.h>
void main()
{
   int no,sum,rem,n;//no=number,sum=sum of cube of each digit in no,rem=remainder, n=copy of no

   //accept value of n
   printf("\nEnter any number: ");
   scanf("%d",&no);

   n=no;//n is copy of number
   sum=0;

   //To find the sum of cubes of each digit in a number
   while(no!=0)
   {
    rem=no%10;
      sum=rem*rem*rem+sum;
      no=no/10;
   }

   //if n is similar to the sum of cubes of each digit in given number then it is Armstrong number
   if(n==sum)
   {
    printf("%d is armstrong number.",sum);
   }
   else
   {
    printf("%d is not armstrong number.",sum);
   }
   getch();
}

0 Comments