直角三角形 awk -f 'as1'
cat as1
BEGIN {
i=1;
while(i<=10) {
j=1;
while(j<=i) {
printf "x";
j++;
}
printf "\n";
i++;
}
}
直角空心三角形 awk -f 'as2'
cat as2
BEGIN {
i=1;
while(i<=10) {
j=1;
while(j<=i) {
if (j==1 || j==i || i==10)
printf "x";
else
printf " "
j++;
}
printf "\n";
i++;
}
}
等腰三角形 awk -f 'as3'
cat as3
BEGIN {
i=1;
while(i<=10) {
j=1;
while(j<=(10-i)) {
printf " ";
j++;
}
j=1;
while(j<=(2*i-1)) {
printf "x";
j++;
}
printf "\n";
i++;
}
}
等腰空心三角形 awk -f 'as4'
cat as4
BEGIN {
i=1;
while(i<=10) {
j=1;
while(j<=(10-i)) {
printf " ";
j++;
}
j=1;
while(j<=(2*i-1)) {
if (j==1 || j==(2*i-1) || i==10 )
printf "x";
else
printf " "
j++;
}
printf "\n";
i++;
}
}
阅读(1967) | 评论(0) | 转发(0) |