KRISHNMURTHY NUMBER PROGRAM IN C

 In this example, you will learn a program to check whether entered number is Krishnamurthy number or not.


Krishnamurthy Number:

A krishnamurthty  number is a number whose sum of the factorial of digits is equal to the number itself. 

Let's take one example:
Suppose we want to check whether 40585

4! + 0! + 5! + 8! + 5!
= 24 + 1 + 120 + 40320 + 120
=40585
i.e. equal to the  number itself.
Hence, 40585 is a Krishnamurthy Number.


Program:


//Program to check whether entered number is krishnamurthy number or not.

#include<stdio.h>
#include<process.h>

int main( )
{
int i,n,a,r,c=0,s;
printf(" 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);
}
return 0;
}

Output:

Enter a number : 40585

40585 is a Krishnamurthy Number.
   ----------------------------------------------------------------------------------------------------------------
    
Enter a number : 90

90 is not a Krishnamurthy Number.




So that's it ! Just try this code by your own. If you have any doubts then feel free to drop a comment . I'll be happy to answer your questions .

Keep coding....

Comments

Popular posts from this blog

DECIMAL TO OCTAL CONVERSION IN C

PROGRAM TO CONVERT BINARY CODE TO GRAY CODE