C program to check if number is Strong number or not

C program to check if number is Strong number or not



Explanation:

A strong number is a number whose sum of factorial digits is equal to number itself.
e.g: 145
1!+4!+5!=1 + 24 + 120 = 145
So, 145 is a strong number.

Program:

#include<stdio.h>
int main()
{
int n,num,i,temp,sum=0,fact=1;
printf("\nEnter number to be checked: ");
scanf("%d",&n);
num=n;
while(num!=0)
{
          i=(int)num%10;
          while(i>1)
                    {
                    fact=fact*i;
                    i--;
                    }
          sum=sum+fact;
          fact=1;
          num=(int)num/10;
}
if(n==sum)
{
          printf("\nStrong Number");
}
else
{
          printf("\nNot Strong Number");
}
return 0;
}
Output:




No comments:

Post a Comment