Home >php教程 >php手册 >php 打印乘法口绝表代码

php 打印乘法口绝表代码

WBOY
WBOYOriginal
2016-05-25 16:46:351169browse

PHP是老师经常会要我们做这个的题目,今天我再做一次打印乘法口决,PHP代码如下:

<?php
/*
 *打印乘法口绝表
*/
echo "九灵九乘法口绝表<br><br><br>";
echo "<table>";
for ($i = 1; $i <= 9; $i++) {
    echo "<tr>";
    for ($j = 1; $j <= $i; $j++) {
        echo "<td>" . $j . "*" . $i . "=" . ($j * $i) . "</td>";
    }
    echo "</tr>";
}
echo "</table>";
echo "<br><br><br><br><br><br>";
echo "<table>";
for ($i = 1; $i <= 9; $i++) {
    echo "<tr>";
    for ($j = $i; $j <= 9; $j++) {
        echo "<td>" . $i . "*" . $j . "=" . ($j * $i) . "</td>";
    }
    echo "</tr>";
}
echo "</table>";
?>

一个简单的求和

<?php
function sum($n) {
    if ($n > 1) {
        return sum($n - 1) + $n;
    } else {
        return 1;
    }
}
echo sum(100);
?>


文章网址:

随意转载^^但请附上教程地址。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn