1080 picture square

Title description

Given an integer n, output a hollow square with side length n consisting of the character "*".

Input requirements

Enter an integer n

Output requirements

Output a hollow square with side length n consisting of characters "*".

Input sample

5

Sample output

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

Reference program

#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;
}

 

Guess you like

Origin blog.csdn.net/weixin_44643510/article/details/113816244