**Question 44 : Write a program in Java to check whether the number given by the user is a Krishna Murthy number or not.**

**Krishna Murthy Number : It is a number which is equal to the sum of the factorials of all its digits.**

**For example : 145 = 1! + 4! + 5! = 1 + 24 + 120 = 145**

**Java Program :**

import java.io.*;

class krishnamurthy

{

int fact(int n)

{

int i,p=1;

for(i=n;i>=1;i--)

p=p*i;

return p;

}

void krishna()throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int a,b,s=0;

System.out.print("Enter the number : ");

a=Integer.parseInt(br.readLine());

System.out.print("\n");

int n=a;

while(a>0)

{

b=a%10;

s=s+fact(b);

a=a/10;

}

if(s==n)

System.out.print(n+" is a krishnamurthy number");

else

System.out.print(n+" is not a krishnamurthy number");

}

}

Working Fine... Just make the factorial part within the main...

ReplyDeletekrisnamurti numbers btween 1 t 1000

ReplyDeletecool part

ReplyDeleteHey can you please help me with String programs for example finding the frequency of each character in the string entered by the user

ReplyDeleteUse length statement as

Deletepublic void main (String s)

int l=s.length();

This the exact Logic I used in making a friends assignment last week

ReplyDeleteI also used a seperate function for the calculation of factorial

:) :)

This is same as that of the special number right???

ReplyDeleteno!! it is diff... special no. is for ex.135...then 1+3+5=9 and 1*3*5*9=135

Deletebut krishna murthy is sum of the factorials of the numbers

thank you very much as it has helped me a lot

ReplyDeleteVery much useful article. Kindly keep blogging

DeleteJava Training in Chennai

Java Online Training India

this means special no. do not name with different to confuse us

ReplyDeleteIt would be better if you did the whole under the main function...

ReplyDeletemade the program very tuff.......

ReplyDeletevery tuff to understand

ReplyDeletemake it a little simple

Can you do it using boolean

ReplyDelete