99 multiplication table with upper and lower left and right symmetry

Source: Internet
Author: User

As shown in title, the 99 multiplication table is almost always available in every technical language, not particularly rare. This article describes the two commonly used loops (for and while) in JavaScript to complete these four symmetrical 99 multiplication tables, an example of a good practice loop basis, which loops a table due to the untidy layout.

One, the lower left corner is a 90-degree trapezoid multiplication table:

For Loop code

1 document.write ("<table width= ' border=0 ' >"), 2 for     (var i=1; i<=9; i++) {3         document.write ("< Tr> ") 4 for         (Var j=1; j<=i; J + +) {5             document.write (" <td> "+ j +" * "+ i +" = "+ I*j +" </td> "); 6         }7         document.write ("</tr>"); 8     }9 document.write ("</table>");

While loop code

1 document.write ("<table width= ' border=0 ' >"); 2 var i = 1; 3 while (i<=9) {4     document.write ("<tr>"), 5     var j = 1; 6 while     (j<=i) {7         document.write (" <td> "+ j +" * "+ i +" = "+ I*j +" </td> "); 8         J + +, 9     }10     document.write ("</tr>"), one     i++;12}13 document.write ("</table>");

Example diagram

Second, the lower right corner is a 90-degree trapezoid multiplication table:

For Loop code

1 document.write ("<table width= ' border=0 ' >"); 2 for (var i=1; i<=9; i++) {3     document.write ("<tr>"), 4 for     (var n=i; n<9; n++) {5         document.write ( "<td>&nbsp;</td>"); 6     } 7 for     (var j=i; j>=1; j--) {8         document.write ("<td>" + j + "*" + i + "=" + I*j + "</td>"); 9     }1 0     document.write ("</tr>");}12 document.write ("</table>");

While loop code

1 document.write ("<table width= ' border=0 ' >"); 2 var i = 1; 3 while (i<=9) {4     document.write ("<tr>"), 5     var n = i, 6 while     (n<9) {7         document.write ("< Td>&nbsp;</td> "); 8         n++; 9     }10     var j = i;11 while     (j>=1) {         document.write ("<td>" + j + "*" + i + "=" + I*j + "</ Td> "),         j--;14     }15     document.write (" </tr> "), i++;17}18     document.write (" </table > ");

Example diagram

Three, the upper left corner of the 90-degree trapezoid multiplication table:

For Loop code

1 document.write ("<table width= ' border=0 ' >"), 2 for (var i=9; i>=1; i--) {3     document.write ("<tr> "); 4 for     (Var j=1; j<=i; J + +) {5         document.write ("<td>" + j + "*" + i + "=" + I*j + "</td>"); 6     }7     document.write ("</tr> "); 8}9 document.write (" </table> ");

While loop code

1 document.write ("<table width= ' border=0 ' >"); 2 var i = 9; 3 while (i>=1) {4     document.write ("<tr>"), 5     var j = 1; 6 while     (j<=i) {7         document.write (" <td> "+ j +" * "+ i +" = "+ I*j +" </td> "); 8         J + +, 9     }10     document.write ("</tr>"), one     i--;12}13 document.write ("</table>");

Example diagram

Four, the upper right corner of the 90-degree trapezoid multiplication table:

For Loop code

1 document.write ("<table width= ' border=0 ' >"); 2 for (var i=9; i>=1; i--) {3     document.write ("<tr>"), 4 for     (var j=8; j>=i; j--) {5         document.write ("<td>&nbsp;</td>"); 6     } 7 for     (var j=i; j>=1; j--) {8         document.write ("<td>" + j + "*" + i + "=" + I*j + "</td>"); 9     }1 0     document.write ("</tr>");}12 document.write ("</table>");

While loop code

1 document.write ("<table width= ' border=0 ' >"); 2 var i = 9; 3 while (i>=1) {4     document.write ("<tr>"), 5     var j = 8; 6 while     (j>=i) {7         document.write (" <td>&nbsp;</td> "); 8         j--; 9     }10     var j = i;11 while     (j>=1) {         document.write ("<td>" + j + "*" + i + "=" + I*j + "</ Td> "),         j--;14     }15     document.write (" </tr> "), i--;17}18     document.write (" </table > ");

Example diagram

99 multiplication table with upper and lower left and right symmetry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.