In this project, the c++ programming language has been used to check the number to be Krishnamurthy Number.

In Mathematics, a Krishnamurthy Number is a number whose sum of the factorial of all its digits is equal to the number itself.

For example- 2 as 2!=2*1=2

145 as 1!+4!+5!=145

To understand the concept and related code basic knowledge of C++ is required.

Here two function have been created in the code:

1. function for factorial of any number:

Factorial of any number n, denoted by n! is the product of that number with all the number less than or equal to n,

for example, 5!=5*4*3*2*1=120. This factorial function will find the factorial of the digits of the number.

The key concept used in this function is n*fact(n-1), in which n is the digit whose factorial is to be calculated and n-1 is the digit one less than the digit.

2.sum of the factorial of the digits of the number:

A variable named sum will be initialized as 0. The target number will be stored in a temporary variable, thus the temporary variable = number. Next under while loop, the concept follows-

i. finding remainder of number in the temporary variable,

ii. adding the factorial of the remainder to sum and then

iii. dividing the number in the temporary variable by 10.

Then out of the while loop, compare sum and number entered to be equal.

Under the main function declare a variable to input any number from the user.

Check for the second function to be true or false, if true then the print number is a Krishnamurthy number otherwise, the print number is not a Krishnamurthy number.

Submitted by Nidhi Vaishya (Nidhi)

Download packets of source code on Coders Packet

## Comments