Strong number is a special number whose sum of factorial of digits is equal to the original number.
For example: 145 is strong number. Since,
For example: 145 is strong number. Since,
1! + 4! + 5! = 145
#include<stdio.h>
int fect(int n){
int i,res=1;
for(i=n;i>0;i--)
res*=i;
return res;
}
int isStrong_Number(int n){
int rem=0,sum=0,temp=n;
while(n){
rem=n%10;
sum+=fect(rem);
n/=10;
}
return sum==temp;
}
void Strong_Number(int no){
int i;
for(i=1;i<no;i++){
if(isStrong_Number(i))
printf("%d\t",i);
continue;
}
}
void main()
{
int no;
printf("Enter the Number check upto Nth Number: ");
scanf("%d",&no);
Strong_Number(no);
}
output:
Enter the Number check upto Nth Number 10000
1 2 145
No comments:
Post a Comment
If you have any doubt . Please let me know