Skip to content

Commit edd69bd

Browse files
Merge pull request #38 from dineshparekh11/dinesh1
Solution of Special Number
2 parents 51822c1 + 901cd55 commit edd69bd

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Number Theory/SpecialNo.java

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

0 commit comments

Comments
 (0)