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

C Exercise 10

C Exercise 10

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Print a staircase, and print two smiling faces above it.

**Analysis:** Use ASCII 1 to print the smiling faces; use i to control rows and j to control columns, with j determining the number of black squares output based on the value of i.

If you encounter garbled characters, please refer to[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

;

printf

(

"

\

1

\

1

\

n

"

)

;

/*

Print two smiling faces

*/

for

(

i

=

1

;

i

<

11

;

i

++

)

{

for

(

j

=

1

;

j

<=

i

;

j

++

)

printf

(

"

%c%c

"

,

219

,

219

)

;

printf

(

"

\

n

"

)

;

}

return

0

;

}

The output of the above example is:

100 Classic C Language Examples 100 Classic C Language Examples