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

C Exercise 88

C Exercise 88

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Read 7 integer values (1-50). Each time a value is read, the program prints that many asterisks (*).

**Analysis:** None.

Example

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

// Copyright (c) 2015 Runoob Tutorial. All rights reserved.

//

#include

<

stdio.h

#include

<

stdlib.h

int

main

(

)

{

int

n

,

i

,

j

;

printf

(

"

Please enter a number:

\

n

"

)

;

i

--;

for

(

i

=

0

;

i

<

7

;

i

++

)

{

scanf

(

"

%d

"

,&

n

)

;

if

(

n

50

)

{

printf

(

"

Please enter again:

\

n

"

)

;

i

--;

}

else

{

for

(

j

=

0

;

j

<

n

;

j

++

)

printf

(

"

"

)

;

}

printf

(

"

\

n

"

)

;

}

return

0

;

}

The above example produces the following output:



Please enter a number:

5

*****

100 Classic C Language Examples 100 Classic C Language Examples