any number is 145
=> 1! + 4! + 5!
=> 1 + 24 + 120
=> 145
The sum of the factorial of individual digits is the same as the original number 145. Hence, 145 is a Krishnamurthy number.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a,r,c=0,s;
clrscr();
printf(" Please,Enter a number : ");
scanf("%d",&n);
if(n==0)
{
printf("\n %d is not a Krishnamurthy Number.",n);
exit(0);
}
a=n;
while(n>0)
{
r=n%10;
s=1;
for(i=r;i>=1;i--)
s=s*i;
c=c+s;
n=n/10;
}
if(c==a)
printf("\n %d is a Krishnamurthy Number.",a);
else
printf("\n %d is not a Krishnamurthy Number.",a);
getch();
}
No comments:
Post a Comment
for more information please share like comment and subscribe