Strong Number Program in C

Previous
Next

Strong Number: Sum of factorials of Individual digits is equals to the same number
n = 145 -> 1! + 4! + 5! -> 1 + 24 + 120 -> 145

#include <stdio.h>
int main()
{
	int n,sum=0,temp,r,fact,i;
	printf("Enter a Number : ");
	scanf("%d",&n);                       
	temp=n;
	while(n!=0)
	{
    	r=n%10;
    	fact=1;
    	for(i=r ; i>=1 ; i--)
    	{
    		fact=fact*i;
    	}
    	sum=sum+fact;
    	n=n/10;
	}
	n=temp;
	if(n==sum)
		printf("%d is Strong \n", n);
	else
		printf("%d is not Strong \n", n);
}
Previous
Next

Courses Enquiry Form