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

C Language Examples - Printing Array Elements

C Language Examples - Printing an Array

C Language Examples C Language Examples

Print an array using a for loop:

Example

#include

<

stdio.h

int

main

(

)

{

int

array

[

10

]

=

{

1

,

2

,

3

,

4

,

5

,

6

,

7

,

8

,

9

,

0

}

;

int

loop

;

for

(

loop

=

0

;

loop

<

10

;

loop

++

)

printf

(

"

%d

"

,

array

[

loop

]

)

;

return

0

;

}

The output is:



1 2 3 4 5 6 7 8 9 0

Print an array in reverse using a for loop:

Example

#include

<

stdio.h

int

main

(

)

{

int

array

[

10

]

=

{

1

,

2

,

3

,

4

,

5

,

6

,

7

,

8

,

9

,

0

}

;

int

loop

;

for

(

loop

=

9

;

loop

=

0

;

loop

--

)

printf

(

"

%d

"

,

array

[

loop

]

)

;

return

0

;

}

The output is:



0 9 8 7 6 5 4 3 2 1

C Language Examples C Language Examples