Various techniques and algorithms can be used to reverse an array, including printing it from the last element, utilizing an auxiliary array, recursion, swapping, etc. Some of the program to reverse the elements of an array is discussed here.
Given an array of integers, all the array elements are reversed.
For example, consider the array
Input:
arr = {1, 2, 3, 4, 5}
Output:
Reversed array: {5, 4, 3, 2, 1}
@@coding::1@@
// The same program, but using POINTERSn#include<stdio.h>nvoid reverse(int n,int *a)n{nint i;nprintf(“Reversed array is:nâ€);nfor(i=n-1;i>=0;i–)n{nprintf(“%dnâ€,a[i]);n}n}nint main()n{nint n,*a,i;nscanf(“%dâ€,&n);nfor(i=0;i<n;i++)n{nscanf(“%dâ€,a+i);n}nreverse(n,a);nreturn 0;n}n
Recommended Programs