Showing posts with label program to reverse the order of elements of an array. Show all posts
Showing posts with label program to reverse the order of elements of an array. Show all posts

Monday, April 11, 2016

c program to reverse the given array in minimum possible complexity

#include<stdio.h>
void main()
{
 int a[10]={7,9,6,8,3,9,6,1,9,5};
 int i;
 int n=10;
 int temp;
 for(i=0;i<n;i++)
  {
   printf("%d ",a[i]);
  }
 for(i=0;i<n/2;i++)
  {
   temp=a[n-i-1];
   a[n-i-1]=a[i];
   a[i]=temp;
  }
 printf("\n");
 printf("Reverse array: ");
 for(i=0;i<n;i++)
  {
   printf("%d ",a[i]);
  }
}

output
7 9 6 8 3 9 6 1 9 5
Reverse array: 5 9 1 6 9 3 8 6 9 7