Wednesday, 3 August 2011

TO CHECK WHETHER THE NUMBER IS SPECIAL NUMBER OR NOT


TO CHECK WHETHER THE NUMBER IS SPECIAL NUMBER OR NOT
ALGORITHM
Step-1 Start
Step-2 Declaration of method for finding the factorial value of any no.
Step-3 Declaration of the main program.
Step-4 Take value from the user.
Step-5 Initialization of variables.
Step-6 Extract each digit from the entered value till its value becomes 0 a send each   digit into the method one by one and add its returning value in a variable in main program.
Step-7 If the sum is equal to the original entered value then the result will be true else false.
Step-7 Exit
PROGRAM
 class special
{
public static long fact(int x)
{
long     i,f=1;
for (i=1;i<=x;i++)
{
f=f*i;
    }
  
 return f;
}
public static void main(int a)
{
special obj = new special();
long r=0,n=a,s=0;
while(a>0)
{
int k=a%10;
r=obj.fact(k);
s=s+r;
a=a/10;
    }
    if (s==n)
        System.out.println("The entered number is special");
        else
        System.out.println("The entered number is not special");
    }
}

VARIABLE DESCRIPTION-

VARIABLE USED
DATATYPE
DESCRIPTION

a
Integer type
For taking the number from the user.
r
Long type
For storing the returning value.
n
Long type
For storing the original number.
s
Long type
For storing the sum of the digits.
k
Integer type
For extracting the last digit of the entered number.




INPUT/OUTPUT-


INPUT
OUTPUT

145

The entered number is special

12345


The entered number is not special

1 comment: