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 a given Matrix using Recursion
- Traverse matrix in L shape
- C Program for Program for array rotation
- Program for array rotation
- Program for product of array
- Program to print Sum of even and odd elements in an array
- Program to reverse an array using pointers
- C Program to Reverse Array of Strings
- Program for Mean and median of an unsorted array
- Program to check if an array is bitonic or not
- Program for multiplication of array elements
- Program to make a histogram of an array
- Program to check if an Array is Palindrome or not
- Program to cyclically rotate an array by one
- Program to find sum of elements in a given array
- Program to print Sum Triangle for a given array
- Program to calculate Bitonicity of an Array
- C/C++ Program to find sum of elements in a given array
- C program to Insert an element in an Array
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.

