Reverse an Array
An array is a contiguous block of memory.To reverse an array we start two variables on both the ends and keep exchanging the values.In this way we can reverse an array in n/2 complexity.
/*
http://www.ProbCOMP.com
An array is a contiguous block of memory.To reverse an array we start two variables on both the ends and keep exchanging the values.
In this way we can reverse an array in n/2 complexity.
*/
#include<stdio.h>
void main()
{
int arr[10]={1,2,3,4,5,6,7,8,9,10},i,j,temp;
printf("array : \t");
for(i=0;i<10;i++)
printf("%d ",arr[i]);
for(i=0,j=9;i<j;i++,j--)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
printf("\nreverse array: \t");
for(i=0;i<10;i++)
printf("%d ",arr[i]);
}
Download Program


