-
Notifications
You must be signed in to change notification settings - Fork 57
/
SpecialNumber
35 lines (33 loc) · 912 Bytes
/
SpecialNumber
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* A number is said to be special number when the sum of factorial of its digits is equal to the number itself. Example- 145 is a Special Number as 1!+4!+5!=145.*/
import java.util.Scanner;
public class SpecialNumber
{
public static void main(String[] args)
{
int n, num, r,
sumOfFactorial = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
r = num % 10;
int fact=1;
for(int i=1;i<=r;i++)
{
fact=fact*i;
}
sumOfFactorial = sumOfFactorial+fact;
num = num / 10;
}
if(n==sumOfFactorial)
{
System.out.println("Special Number" );
}
else
{
System.out.println("Not Special Number" );
}
}
}