BC7 Two ways to solve the character rectangle of Niu Niu

topic 

describe

Niu Niu tries to read a character using the keyboard, and then displays a 3*3 rectangle composed of this character on the screen.

Enter description:

Read one char type character per line.

Output description:

Output a 3*3 rectangle composed of this character.

Solution 1: Conventional output method

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
    char a=0;
    scanf("%c",&a);
    printf("%c%c%c\n",a,a,a);
    printf("%c%c%c\n",a,a,a);
    printf("%c%c%c",a,a,a);
    return 0;
}

Solution 2: Use a loop to write (for)

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
    char a=0;
    scanf("%c",&a);

    int i;
    for(i=0;i<3;i++)
    {
        int b;
        for(b=0;b<3;b++)
        {
            printf("%c",a);
        }//内层循环,有三列
        printf("\n");//每打印完三个字符要换行
    }//外层循环,有三行
    return 0;
}

Test results: (input a)

 Note: When using the VS compiler, if you need to use the scanf function,

           The first line of the source code should be #define _CRT_SECURE_NO_WARNINGS

Guess you like

Origin blog.csdn.net/weixin_70464416/article/details/132026309