# C program to traverse an Array

Given an integer array of size **N**, the task is to traverse and print the elements in the array.**Examples:**

Input:arr[] = {2, -1, 5, 6, 0, -3}Output:2 -1 5 6 0 -3We provide nothing but the best curated videos and practice problems for our students. Check out theC Foundation Courseand master the C language from basic to advanced level. Wait no more, start learning today!

Input:arr[] = {4, 0, -2, -9, -7, 1}Output:4 0 -2 -9 -7 1

**Approach:-**

1. Start a loop from **0** to **N-1**, where **N** is the size of array.

for(i = 0; i < N; i++)

2. Access every element of array with help of

arr[index]

3. Print the elements.

printf("%d ", arr[i])

Below is the implementation of the above approach:

## C

`// C program to traverse the array` `#include <stdio.h>` `// Function to traverse and print the array` `void` `printArray(` `int` `* arr, ` `int` `n)` `{` ` ` `int` `i;` ` ` `printf` `(` `"Array: "` `);` ` ` `for` `(i = 0; i < n; i++) {` ` ` `printf` `(` `"%d "` `, arr[i]);` ` ` `}` ` ` `printf` `(` `"\n"` `);` `}` `// Driver program` `int` `main()` `{` ` ` `int` `arr[] = { 2, -1, 5, 6, 0, -3 };` ` ` `int` `n = ` `sizeof` `(arr) / ` `sizeof` `(arr[0]);` ` ` `printArray(arr, n);` ` ` `return` `0;` `}` |

**Output:**

Array: 2 -1 5 6 0 -3

**Time Complexity: **O(n)

**Auxiliary Space: **O(1)