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 -3Input: arr[] = {4, 0, -2, -9, -7, 1}
Output: 4 0 -2 -9 -7 1
Approach:-
- Start a loop from 0 to N-1, where N is the size of array.
for(i = 0; i < N; i++)
- Access every element of array with help of
arr[index]
- 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; } |
Array: 2 -1 5 6 0 -3
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Shortest path to traverse all the elements of a circular array in increasing order
- Traverse matrix in L shape
- Traverse a given Matrix using Recursion
- C Program for Program for array rotation
- C Program for Program to find area of a circle
- Lex Program to remove comments from C program
- Find original array from encrypted array (An array of sums of other elements)
- Find Array formed by adding each element of given array with largest element in new array to its left
- Array obtained by repeatedly reversing array after every insertion from given array
- Find an element in array such that sum of left array is equal to sum of right array
- Program for array rotation
- Write a program to reverse an array or string
- Program to check if an array is sorted or not (Iterative and Recursive)
- Program to find sum of elements in a given array
- Program to find largest element in an array
- Program to cyclically rotate an array by one
- Recursive program to linearly search an element in a given array
- Program to print Sum Triangle for a given array
- Program to print an array in Pendulum Arrangement
- Program for multiplication of array elements
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

