WAP to check whether a number is strong number or not.

If the sum of the factorials of digits of a number is equal to the original number.
 Ex: n=145=> 1! + 4! + 5! = 1 + 24 + 120 = 145
 then it is strong number.
 #include<stdio.h>
 #include<stdlib.h>

 int fact(int num);
 int main()
 {
 int n,num,i,sum=0,rem,f;
printf("Enter a number: ");
 scanf("%d",&n);
 num=n;
 while(n>0)
 {
 rem=n%10;
 f=fact(rem);
 sum=sum+f;
 n=n/10;
 }
printf("%d",sum);
 if(sum==num)
 printf("strong number");
 else
 printf("not a strong number\n");
 system("pause");
 return 0;
 }
int fact(int n)
 {
 int j,f=1;
 for(j=n;j>=1;j--)
 {
 f=f*j;
 }
 return(f);
 }
Advertisements

Leave a comment

Filed under TUTORIALS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s