C Exercise Example 9

100 Classic C Examples

Title:Requirement: output an international chessboard.

Program analysis:The chessboard consists of 64 alternating black and white squares, arranged in 8 rows * 8 columns. Use i to control the row and j to control the column, and decide whether to output a black square or a white square based on the sum of i+j.

If garbled characters appear, please refer to this blog.[C Practice Example 7]The solution method.

Example

// Created by www.example.com on 15/11/9. // Copyright © 2015 Example. All rights reserved. // #include<stdio.h> int main() { int i,j; 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"); } return 0; }

The output result of the above example is:

100 Classic C Examples

other extensions