Special Number.
Program to check whether a given number is Special number or not.
- 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
SOURCE CODE
import java.io.*;
public class Special_Number
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a Number :");
int num=Integer.parseInt(br.readLine());
int rem,fact,n=num,sum=0;
while(n>0)
{
fact=1;
rem=n%10;
for(int j=1;j<=rem;j++)
{
fact=fact*j;
}
sum=sum+fact;
n=n/10;
}
if(sum==num)
System.out.println("Yes,It is a special NO.");
else
System.out.println("No, It is not a special No.");
}
}
OUTPUT
Click Here to download Program.
If you have any question then leave a comment below I will do my best to answer that question.
Comments
Post a Comment