F How Can We Implement Reverse Of An Array Elements? | CodeTheta

How Can We Implement Reverse Of An Array Elements?

May 09, 2014

This program will help you to show reverse element of an array. When you will executing this program you will see that, program will ask you for the array limit as you can see in the output picture in below. After the memory limit is given program will ask you for allocate the element, when all have done properly the program will shows you the reverse array element.


/* http://native-code.blogspot.com */

#include<stdio.h>
#include<conio.h>
#define MAX 20
void rv_arr(int [], int, int);
void main()
{
int a[MAX], n, x, i;
n=x=0;
printf("/* http://native-code.blogspot.com */");
printf("\nEnter limit:\n");
scanf("%d", &n);
printf("\nEnter elements:\n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
printf("\nBefore:");
for(i=0; i<n; i++)
{
printf("%d ", a[i]);
}
rv_arr(a, 0, n-1);
printf("\n\nAfter:");
for(i=0; i<n; i++)
{
printf("%d ", a[i]);
}
getch();
}
void rv_arr(int a[], int x, int y)
{
int tmp, i;
tmp=i=0;
if(x>y)
return;
else
{
tmp=a[y];
a[y]=a[x];
a[x]=tmp;
rv_arr(a, ++x, --y);
}
}


/* http://native-code.blogspot.com */
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us

Post a Comment