Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 9

C Exercise 9

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Print a chess board.

**Program analysis:** A chess board consists of 64 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 print a black or white square based on the value of i+j.

If garbled characters appear, please refer to this blog[C Exercise 7]for the solution.

Example

// Created by www.runoob.com on 15/11/9.

// Copyright (c) 2015 Runoob Tutorial. 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 of the above example is:

100 Classic C Language Examples 100 Classic C Language Examples