Tuesday, July 28, 2020

Write a program to input a number and check whether it is Special number (krishnamurti number, strong number) or not? (145=1!+4!+5!=1+24+120=145)

59)  Write a program to input a number and check whether it is Special number (krishnamurti number, strong number) or not? (145=1!+4!+5!=1+24+120=145)


import java.util.*;
public class Special_number
{
   public static void main(String args[ ])
   {
              Scanner sc = new Scanner (System.in);
              System.out.println("Enter a number");
              int a = sc.nextInt();
              int k = a;
              int s = 0;
              while(k>0)
              {
                  int d = k%10;
                  int p = 1;
                  for(int i = 1;i<=d;i++)
                  {
                      p=p*i;
                  }
                  s=s+p;
                  k=k/10;
              }
              if(s==a)
              {
                  System.out.println("Entered number is SPECIAL(KRISHNAMURTI,STRONG) Number ");
              }
              else
              {
                   System.out.println("Entered number is not a SPECIAL(KRISHNAMURTI,STRONG) Number ");
              }
   }
}

Output : 


 


No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj