DEV Community

Sivakumar Mathiyalagan
Sivakumar Mathiyalagan

Posted on

Strong Number

What is Strong number?
A strong number (also called a factorial number) is a number whose value is equal to the sum of the factorials of its digits

Example

Take 145:

1! = 1
4! = 24
5! = 120

Now add them:

1 + 24 + 120 = 145

Since the sum equals the original number, 145 is a strong number.

Code:
//Strong Number

let givenNumber = 145;
let ogNum = givenNumber;
let count =1;
let rem =0;
let total =0;

while(givenNumber>0)
{
rem = givenNumber%10
let newRem = 1;
while(rem > 0)
{
newRem= newRem*rem
rem--
}
total = total+newRem;
givenNumber=Math.floor(givenNumber/10);
}
console.log(total);
if(total == ogNum ){
console.log("number is a strong number")
}
else{
console.log("not a strong number")
}

Top comments (0)