Home » NO IDEA » Strong Number

Strong Number

Blog Stats

  • 13,912 hits
December 2012
M T W T F S S
« Sep   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

STRONG NUMBER

Definition of strong number:
 
A number is called strong number if sum of the factorial of its digit is equal to number itself. For example: 145 since
1! + 4! + 5! = 1 + 24 + 120 = 145

#include<stdio.h>
int r;
int main()
{
int num,check,i;
int totfact=0;
int fact;

printf("\n Enter the number");
scanf("%d",&num);
check=num;
while(num)
{
r=num%10;
fact=1;
for(i=1;i<=r;i++)
{
fact=fact*i;
}
num=num/10;
totfact=totfact+fact;

}
if(check==totfact)
{
printf("%d=IT IS AN STRONG NUMBER",check);
}
else
{
printf("%d=IT IS AN NOT STRONG NUMBER",check);
}

return 0;
}

//generation of the strong number
#include<stdio.h>
int main(){
int num,i,f,r,sum,temp;
int min,max;

printf("Enter minimum range: ");
scanf("%d",&min);

printf("Enter maximum range: ");
scanf("%d",&max);

printf("Strong numbers in given range are: ");
for(num=min; num <= max; num++){
temp = num;
sum=0;

while(temp){
i=1;
f=1;
r=temp%10;

while(i<=r){
f=f*i;
i++;
}
sum=sum+f;
temp=temp/10;
}

if(sum==num)
printf("%d ",num);
}
return 0;
}
Advertisements

1 Comment

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

%d bloggers like this: