Computer Science, asked by gsalu582, 10 months ago

write a program to print all the Krishnamurthy number from 1 to N is user dependent Krishnamurthy number is whose number sum of factorial of individual digits equal the number ​

Answers

Answered by parnad2018kolkata
2

Answer:  Krishnamurthy Number.

Giving the code in java language.

Explanation:

import java.uti.*;

class Krishnamurthy

{

      public static void main(String args[])

{

   Scanner sc=new Scanner(System.in);

System.out.println("Enter the value of N=");

int n=sc.nextInt()

for(int i=1;i<=N;i++)

{

krishnamurthy(i);

}

}

void  krishnamurthy(int a ) // method to check if krishnamurthy

{ int t,s=0,r;

t=n;

 while(t>0)

{    r=t%10;

  s+= factorial(r);

   t=t/10;

}

if(s==a)

System.out.println("It is a krishnamurthy number");

else

System.out.println("It is not a krishnamurthy number");

}          

int  factorial (int b) // method for calculating factorial

{

int p=1;

for(int i=1;i<=b ;i++)

      {    p*=i;

}

return p;

}

} // end of class

#answerquality & #BAL

Similar questions