Viết chương trình HTML/JS: nhập số n, in mẫu tam giác số.
Ví dụ n=5:
01 01 02 01 02 03 01 02 03 04 01 02 03 04 05
Ví dụ
<html>
<head>
<title>JavaScript Number Patterns</title>
<script>
const printPattern = () => {
const num = document.getElementById("rows").value;
for (let m = 1; m <= num; m++) {
for (let n = 1; n <= m; n++) document.write("0" + n + " ");
document.write("<br />");
}
};
</script>
</head>
<body>
<p>Nhập số hàng và bấm In</p>
<input type="number" placeholder="Số hàng" id="rows">
<button type="button" onclick="printPattern()">In</button>
</body>
</html>
Kết quả
Giao diện nhập số, bấm In hiển thị mẫu tam giác số.