Solution:
<html>
18
<head>
<script language="JavaScript">
function factors()
{
var n=form1.txtNum.value;
var num_factors = [], i;
for (i = 1; i <= Math.floor(Math.sqrt(n)); i += 1)
if (n % i === 0)
{
num_factors.push(i);
if (n / i !== i)
num_factors.push(n / i);
}
alert("factors are:"+" " + num_factors);
}
</script>
</head>
<body>
<form name="form1">
Enter the Number :
<input type="text" name="txtNum">
<input type="button" value="Display" onclick="factors();">
</form>
</body>
</html>
0 Comments