-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor循环相关-金字塔,乘法表
56 lines (50 loc) · 1.28 KB
/
for循环相关-金字塔,乘法表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>这是与爸爸的</title>
<script>
// 倒三角
for(a=5;a>=1;a--){
for(b=0;b<a;b++){
document.write("a");
}
document.write("<br />")
}
document.write("<br />")
// 金字塔
for(i=1;i<=5;i++){//i控制行数
for(m=0;m<5-i;m++){//m控制每一行输入空格的个数,规律:每行空格的个数为输入的总行数减去所在行个数
document.write("-");//每次输出一个空格,不换行
}
for(n=1;n<=2*i-1;n++){//n控制每一行输入*的个数,规律:2*n-1,如第一行1个,第二行2*2-1,。。。。。。
document.write("c");//每次输出一个*,不换行
}
document.write("<br />");//换行
}
document.write("<br />")
// for (a=5;a>=1;a--) {
// for (m=4-a;m>=0;m--) {
// document.write("-");
// }
// for (n=1;n<=2*a-1;n++) {
// document.write("n");
// }
// document.write("<br />");
// }
// 乘法表
for(a=1;a<=9;a++){
for (b=1;b<=a;b++) {
document.write(a+"*"+b+"="+a*b);
if (a != b) {
document.write("   ")
}
}
document.write("<br />")
}
//
</script>
</head>
<body>
</body>
</html>