Computer Science, asked by ankita200411, 1 year ago

Wap in java to check whether a number is Krishnamurthy number or not




plz guys plzz help me​

Answers

Answered by sushiladevi4418
3

Answer:

Wap in java to check whether a number is Krishnamurthy number or not.

Explanation:

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");

   }

}

Output:-

N = 145

YES, 145 is a Krishnamurthy number

Answered by 46mishra
2

Answer:

please mark me brainlist

Attachments:
Similar questions