pjs/js/jsdj/ifcui/run/samples/recursion.html

48 строки
700 B
HTML

<HTML>
<HEAD>
<title>Recursion Sample</title>
<SCRIPT LANGUAGE="Javascript">
function Power(nX, nY)
{
if (nY == 0)
return 1;
if (nY == 1)
return nX;
return (nX * Power(nX, (nY - 1)));
}
function Fact(nArg)
{
if (nArg == 0)
return 1;
if (nArg == 1)
return 1;
return (nArg * Fact(nArg - 1));
}
</SCRIPT>
</HEAD>
<BODY>
<B>Recursion:</B><BR>
<SCRIPT LANGUAGE="Javascript">
document.write("<PRE>");
for (i = 0; i < 15; i++) {
document.writeln("2^" + i + " = " + Power(2, i));
}
document.write("<HR>");
for (i = 0; i < 15; i++) {
document.writeln("" + i + "! = " + Fact(i));
}
document.write("</PRE>");
</SCRIPT>
</BODY>
</HTML>