PROGRAM : SPECIAL NUMBER
Check whether a number is Special Number in JAVA. This program checks whether a number is a 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
SYNTAX:
import java.io.*;
class special_number
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
int n1=n;int d=0,sum=0,f=1;
while(n!=0)
{f=1;
d=n%10;
for(int i=1;i<=d;i++)
{f*=i;
}
sum+=f;
n=n/10;
}
if(sum==n1)
System.out.println("YES THE NUMBER IS SPECIAL NUMBER");
else
System.out.println("NO THE NUMBER IS NOT SPECIAL NUMBER");
}
}
Check whether a number is Special Number in JAVA. This program checks whether a number is a 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
SYNTAX:
import java.io.*;
class special_number
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
int n1=n;int d=0,sum=0,f=1;
while(n!=0)
{f=1;
d=n%10;
for(int i=1;i<=d;i++)
{f*=i;
}
sum+=f;
n=n/10;
}
if(sum==n1)
System.out.println("YES THE NUMBER IS SPECIAL NUMBER");
else
System.out.println("NO THE NUMBER IS NOT SPECIAL NUMBER");
}
}
Comments
Post a Comment