Sunday, September 12, 2010

C Program to print Krishnamurthy Number

#include<stdio.h>
#include<conio.h>
void main()
{
int temp,n,fact,num,sum=0,i;
clrscr();
printf("Enter the Number: ");
scanf("%d",&num);
temp=num;
sum=0;
while(temp>0)
{
n=temp%10;
fact=1;
for(i=1;i<=n;i++)
fact=fact*i;
sum=sum+fact;
temp=temp/10;
}
if(sum==num)
printf("\nKrishnamurthy's Number :");
else
      printf("\n Not a Krishnanurthy's Number ");
getch();
}















2 comments:

  1. good effort ......
    but it would have been nice from your part if could have mentioned what a krishnamurthy number is before you wrote your code...
    Any way a krishnamurthy number is one in which sum of the factorial of the digits of that number gives you the same number .for exambple 145=1!+4!+5!

    ReplyDelete
  2. there are some mistakes in the program.....
    you have not declared n in int which you used in for loop statement
    for(i=1;i<=n;i++)

    ReplyDelete