Problem
Statement
In
this program we will code a basic program to check whether a given number is
Strong number or not
If
sum of factorials of digits, equals the given number,then it is STRONG else it
ISN’T.
Code
#include
int factorial(int rem)
{
int fact=1;
int i;
for(i=1;i<=rem;i++)
{
fact=fact*i;
}
return fact;
}
int main()
{
int n;
int sum=0,rem=0;
int num;
printf("ENTER THE NUMBER \n");
scanf("%d",&n);
num=n;
while(num>0)
{
rem=num%10;
sum=sum+factorial(rem);
num=num/10;
}
if(n==sum)
{
printf("IT IS A STRONG NUMBER \n");
}
else
{
printf("IT IS NOT A STRONG NUMBER \n");
}
return 0;
}
Output
ENTER
THE NUMBER -> 145
IT
IS A STRONG NUMBER
Explanation
Here, in our code we made a seperate function in order to calculate the factorial of a number.So approach is to break the given number into seperate digits,find their factorial and then add them.If sum of factorials of digits equals the given number,then it is STRONG else it ISN’T.


0 Comments