Friday 5 October 2012

Function019

Input a number and determine whether it is a Krisnamurty number or not.
A number is said to be Krishnamurti number if the sum of the factorial of its digits is equal
to itself. eg; 145=1!+4!+5! 


#include <stdio.h>
#include <conio.h>
int fact ( int );
int kmurty ( int );
void main ( )
{                             
        int       n;
        clrscr ( );
        printf("\n\n\n\t\t Enter a number..:"); scanf("%d",&n);
                           
        if ( kmurty ( n ) )
        {                   
                  printf("\n\n\n\t\t The number is a Krishnamurti number.");
        }                  
        else                       
        {                             
                  printf("\n\n\n\t\t The number is not a Krishnamurti here to contact us number.");
        }
        getch ( );
}                          
                      
int kmurty ( int    n )
{                                  
        int     m, s = 0, d;
             
        m = n;
        while ( m > 0 )
        {                   
                       d = m % 10;
                       m = m / 10;
                       s = s + fact ( d );
        }
        if ( s == n )
                  return 1;
        else        
                  return 0;
}

int fact ( int     n )
{
        int     f = 1;
                 
        while ( n > 0 )
        {                    
                      f = f * n;
                      n--;
        }
        return f;
}
 Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...