C program to check strong number
In this program, I have discussed about how to check strong number.
145 is called a strong number because the sum of factorial of its digits is equal to that number, i.e., 1!+4!+5!=145.
Strong numbers are also called as special numbers.
int fact(int);
int main()
{ int n,i,j,sum=0,k,num;
printf("Enter a number :");
scanf("%d",&n);
num=n;
while(n!=0)
{ k=n%10;
j=fact(k);
sum+=j;
n=n/10;
}
if(sum==num)
{ printf("Strong Number");
}
else
{ printf("Not a strong number");
}
}
int fact( int g)
{ int l=1,i;
for(i=1;i<=g;i++)
{ l*=i;
}
return l;
}
Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.
Enjoy programming in C.
0 comments:
Post a Comment