php factorial

php factorial

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>php阶乘</title>
</head>

<body >
<?php
if (isset($_POST['button'])) {
    $num = $_POST['num'];
    if ($num =='' || ! is_numeric($num) || $num < 0) 
    {
        echo '请输入大于等于0的数字';
    } 
    else 
    {
        $num+= 0;
	
        if (true)
        {
            if ($num==0) 
            {
                echo '0!是1';
            } 
            else 
            {
                $result=1;
                for($i=1;$i<=$num;$i++)
                {
                    $result*=$i;
                }
                echo "{$num}!是{$result}";
            }
        }
        else
        {
            echo '您收入的不是整数';
        }
    }
}
?>
<form action="" method="post" name="form1">
		<table width="500" border="1">
			<tr>
				<th colspan="2">求阶乘</th>
			</tr>
			<tr>
				<td>请输入一个数</td>
				<td><input name="num" id="num" type="text" /></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input type="submit" name="button"
					id="button" value="提交" /></td>
			</tr>
		</table>
	</form>
</body>
</html>

Published 70 original articles · won praise 1 · views 504

Guess you like

Origin blog.csdn.net/zhupengqq1/article/details/103943415