A Way For Learning

Strong Number

No comments
Strong Number :
A number is defined as Strong Number if the sum of the factorial of individual digits is equal to the number itself.

Eg: 145
       1!+4!+5!= 1+24+120 = 145
Some of the Strong Numbers are 1,2,145.

Java Program to display Strong Numbers in a given range:

public class StrongNumber{
     public static void main(String []args){
        int range = 100
        for(int i=0; i<range; i++){
            int temp= i;
            int sum=0;
            int sum = factorialSum(i);
            if(sum == i){
                System.out.println(i);
            }
        }
     }
     int factorialSum(int number){
         int sum =0;
         while(number!=0){
             int a= number%10;
             int b=1;
             while (a>0){
                 b=b*a;
                 a--;
             }
             sum=sum+b;
             number= number/10;
         }
         return sum;
     }
}





No comments :

Post a Comment