Skip to content

Commit 916a92b

Browse files
Solution of Speacial Number
1 parent eb1948a commit 916a92b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Number Theory/SpecialNo.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java.util.Scanner;
2+
3+
public class SpecialNo {
4+
public static void main(String[] args) {
5+
Scanner in=new Scanner(System.in);
6+
int num, digit, sum=0, temp;
7+
8+
9+
System.out.println("Enter any number"); // Input the number from user
10+
num = in.nextInt();
11+
temp = num;
12+
13+
14+
while(temp != 0){
15+
digit = temp%10; //Find the factorial of its digits.
16+
sum += factorial(digit); // Add all the factorial.
17+
temp = temp/10;
18+
}
19+
20+
21+
if(sum == num) //Check if the computed sum is equal to the original number.
22+
System.out.println("Given number is Special Number");
23+
else
24+
System.out.println("Not a Special Number");
25+
26+
}
27+
28+
29+
private static int factorial(int n){ //function to compute the factorial of the digits
30+
int f=1;
31+
for(int i=2; i<=n; i++){
32+
f = f*i;
33+
}
34+
return f;
35+
}
36+
}

0 commit comments

Comments
 (0)