文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>awk用while循环打印三角形,直角,空心直角,等腰,等..

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++;
        }
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载