C language brush questions - chess board

insert image description here

Article directory

topic

Output the chess board.
insert image description here

ideas

Use i to control the row, j to control the column, according to the change of the sum of i+j to control the output black square or white square.

Note that the numbers 128 to 255 are extended codes and are not originally used for display. Change the code page of the console that executes this program to 437.

answer

#include <stdio.h>
#include <windows.h>

int main()
{
    
    
    int i,j;
    SetConsoleOutputCP(437);
    for(i=0;i<8;i++)
    {
    
    
        for(j=0;j<8;j++)
        {
    
    
            if((i+j)%2==0)
            {
    
    
                printf("%c%c",219,219);
            }
            else
            {
    
    
                printf("  ");
            }
            
        }
        printf("\n");
    }
}

Sample output

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/qq_21484461/article/details/123997698