Write a program to check strong number?
A strong number said to be if sum of factorial of each digit
from n is equal to given number
i.e 145 = 1!
+ 4! + 5!
= 1
+ 24 + 120
=145
/* ***********************************
Girfa : Student Help
Strong Number Program
for more program visit :http://girfahelp.blogspot.in/p/number-programming-c-language.html
************************************/
#include<stdio.h>
int fact(int);
void main()
{
int n,m,s=0;
printf("Enter Number>>
");
scanf("%d",&n);
m=n;
while(n>0)
{
s=s+fact(n%10);
n=n/10;
}
if(s==m)
printf("\n\t%d is Strong
Number",m);
else
printf("\n\t%d is not a
Strong Number",m);
}
int fact(int n)
{
if(n==0)
return 1;
else
return(n*fact(n-1));
}
No comments:
Post a Comment