for循环实现 九九乘法表,以下示例代码

php实例代码

<?php
header("Content-Type: text/html; charset=utf-8");
for($i = 1; $i <= 9; $i++)
{
for($j = 1; $j <= 9; $j++)
{
    if($j <= $i)
    {
        $h = $i * $j;
        echo "[{$j}x{$i}={$h}]\t";
    }else{
        echo "<br>";
        break;
    }
}
}
?>

99php


Python实例代码

pymath = ''
for i in range(1, 10):
    for j in range(1, 10):
        jci = j * i
        pymath += u"%d*%d=%d\t" % (j, i, jci)
        if j == i:
            pymath += u"\n"
            break
print(pymath) 

99py


c语言实例代码

#include <stdio.h>
void main()
{
    int a, i, j;
    for(i = 1; i < 10; i++)
    {
        for (j = 1; j < 10; j++)
        {
        if (j <= i)
        {
            a = j * i;
            printf("%d*%d=%d\t", j, i, a);
        }
        else
        {
            printf("\n");
            break;
        }
    }
}
printf("\n\n\n");
}

99c


javascript实例代码

document.write('<html><head><title>九九乘法口诀</title></head><body></body></html>');
var html = ''; for(let i = 1; i <= 9; i++) {
for(let x = 1; x <= 9; x++)
{
    if (i >= x)
    {
        let r = x * i;
        html += x + '*' + i + '=' + r + "\t";
    }else{
        html += "<br>";
        break;  
    };
};
}; document.body.innerHTML = html;

99c

文章目录