Easy Tutorial
❮ C Exercise Example43 C Examples Even Odd ❯

C Exercise Example 9

C Language Classic 100 Examples

Title: Requirement to output a chessboard.

Program Analysis: The chessboard consists of 64 alternating black and white squares arranged in 8 rows by 8 columns. Use i to control rows and j to control columns, and based on the sum of i and j, determine whether to output a black square or a white square.

If you encounter garbled characters, please refer to the solution in C Exercise Example 7 of this blog.

Example

//  Created by www.tutorialpro.org on 15/11/9.
//  Copyright © 2015年 tutorialpro.org. All rights reserved.
//

#include<stdio.h>

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

The above example outputs:

C Language Classic 100 Examples

❮ C Exercise Example43 C Examples Even Odd ❯