The following code shows how to Find whether a number is a strong number or not. Basically, a strong number is the one which has the sum of factorials of each digit equals to the number itself. For instance, let n=145. So, 1!+4!+5!=1+24+120=145. Hence, 145 is a strong number. On the other hand, let n=421. So, 4!+2!+1!=24+2+1=27. Therefore, it is not a strong number.
<html>
<head>
<title>Strong Number</title>
<script>
function findstrongnumber(){
let num=prompt("Enter a number: ");
num=Number(num);
t=num;
sum=0;
while(t!=0)
{
rem=t%10;
fac=factorial(rem);
sum+=fac;
t=Math.floor(t/10);
}
if(num==sum)
{
str=num+" is a strong number!";
}
else{
str=num+" is not a strong number!";
}
var v=document.getElementById("mydiv");
v.innerText=str;
}
function factorial(n){
let f=1;
for(let i=1;i<=n;i++)
{
f=f*i;
}
return f;
}
</script>
<style>
body{
margin: 20px;
}
.c{
margin-top: 50px;
padding: 20px;
font-size: 20px;
border: 6px solid #ddaa22;
border-radius: 6px;
}
</style>
</head>
<body>
<center>
<button onclick="findstrongnumber()" class="c">Find Strong
Numbers</button>
</center>
<div id="mydiv"></div>
</body>
</html>
Output