Write a java program to display all the three digits special numbers.
[ hint :- if the original number and sum of the factorial of each digit are same
then number is a special number]
For example :-
N=145
1!+4!+5!=145
145 is special number.
Answers
Answered by
4
Question:-
Write a java program to display all the 3 digit special numbers.
Program:-
class Special
{
static int Factorial(int n)
{
int f=1L;
for(int i=1;i<=n;i++)
f*=i;
return f;
}
public static void main(String s[])
{
for(int i=100;i<1000;i++)
{
int a=i, s=0;
while(a!=0)
{
int d=a%10;
s+=Factorial(d);
a/=10;
}
if(s==i)
System.out.print(i+" ");
}
}
}
Similar questions
Social Sciences,
2 months ago
Hindi,
2 months ago
Hindi,
2 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago
Music,
10 months ago