Write a program to check given number is strong number or not

// Write a program to check given number is strong number or not
// Eg: 145-> 1!+4!+5! = 145 -> Strond

 
#include
int main(){
int inp,i,j,r,sum=0,fact;
printf("Enter a number:");
scanf("%d",&inp); // input from user
if(inp>0)
{
for(i=inp;i!=0;i=i/10)
{
r=i%10;
fact=1;
for(j=1;j<=r;j++)
fact=fact*j;
sum=sum+fact;
}
if(sum==inp) // checking if strong number
printf("Given number is Strong number\n");
else
printf("Given number is not Strong number\n");
}
else
printf("Given number is not Strong number\n");
return 0;
}

No comments:

Post a Comment