1080 画正方形

题目描述

给定一个整数n,输出一个由字符“*”组成的边长为n的中空的正方形。

输入要求

输入一个整数n

输出要求

输出一个由字符“*”组成的边长为n的中空的正方形。

输入样例

5

输出样例

*****
*   *
*   *
*   *
*****

参考程序

#include<stdio.h>

int main()
{
    int n,row,column;//行、列

    scanf("%d",&n);
    for(row=0;row<n;row++)//行扫
    {
        for(column=0;column<n;column++)//列扫
        {
            if(row==0||row==n-1)//首行、尾行
                printf("*");
            else//除了首行、尾行
            {
                if(column==0||column==n-1)//首列、尾列
                    printf("*");
                else//除了首列、尾列
                    printf(" ");
            }
        }
        printf("\n");//每行结束进行换行
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44643510/article/details/113816244
今日推荐