// STRONG NUMBER
/*
for example 145
1! = 1
4! = 24
5! = 120
1 + 24 + 120 = 145 is a STRONG NUMBER
*/
#include<stdio.h>
int main()
{
int n,TEMP,REM,SUM=0,FACT,i;
printf("Enter any integer value : ");
scanf("%d",&n);
TEMP=n;
while(n!=0)
{
REM=n%10;
FACT = 1;
for(i=1;i<=REM;i++)
{
FACT = FACT*i;
}
SUM = SUM+FACT;
n=n/10;
}
if(SUM==TEMP)
{
printf("Strong Number");
}
else
{
printf("Not a Strong Number");
}
return 0;
}
// STRONG NUMBER Series
#include<stdio.h>
int main()
{
int i,j,TEMP,REM,SUM=0,FACT;
printf("Strong Numbers between 1 to 1000 are :\n");
for(i=1;i<=1000;i++)
{
TEMP=i;
while(TEMP!=0)
{
REM=TEMP%10;
FACT = 1;
for(j=1;j<=REM;j++)
{
FACT = FACT*j;
}
SUM = SUM+FACT;
TEMP=TEMP/10;
}
if(SUM==i)
printf("%d ",i);
SUM = 0;
}
return 0;
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.