e.g.
n=36→18→8 the persistence of 36 is 2
n=39→ 27→14→4 the persistence of 39 is 3
Find 2 digit no with max persistance
<HTML>
<HEAD><title>Highest Persistance by kbkashid</title>
<script>
function find()
{
var n,temp,p=1
var cnt=0
var max=0
n=36
for(i=10;i<=99;i++)
{
cnt=0
n=i
while(n>=10)
{
p=1
while(n>0)
{
p=p*(n%10)
n=Math.floor(n/10)
} //while1
cnt=cnt+1
n=p
}//while2
if(cnt>max)
{
max=cnt
temp=i
}
}//for
alert(" Two digit no: " +temp+" has Max Persistence "+max )
}
</script>
</HEAD>
<BODY>Find 2 digit no with max persistance
<INPUT type=button value=Find onclick="find();">
</BODY>
</HTML>
No comments:
Post a Comment
Thanks for visiting my Blog!