Easy to master Krishnamurthy Number (Example – 145)
- Categories Java
Accept a number from user and print if given number is Krishnamurthy number or special number or not.
KN Special number: A special number is a number whose sum of factorial of digits is equal to the number
For example 145 = 1! + 4! + 5!
Watch our video on how to solve any Number Program – Click Here
import java.util.Scanner;
public class KNSpecialNumber {
public static void main()
{
Scanner sc = new Scanner(System.in);
int n;
System.out.println("Enter any number:");
n= sc.nextInt();
int m = n;
int sum = 0;
while (n != 0) {
int d = n%10;
int fact = 1;
for (int i= 1; i<= d; i++)
fact = fact * i;
sum = sum + fact;
n = n / 10;
}
if ( sum == m)
System.out.println ("yes");
else
System.out.println ("no");
}
}
Also watch Automorphic Number Program - Click Here
Tag:special number
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021