awk用while循环打印三角形,直角,空心直角,等腰,等..
时间:2009-08-10 来源:ccjsj1
直角三角形 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++;
}
}
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++;
}
}
相关阅读 更多 +