Sunday, October 16, 2011

Reverse Array

#include<stdio.h>
#include<conio.h>
#include<conio.h>
void main()
{
   int n, c, j, temp, a[100];
   clrscr();
   printf("Enter the number of elements in array\n");
   scanf("%d",&n);
   printf("Enter the array elements\n");
   for ( c = 0 ; c < n ; c++ )
      scanf("%d",&a[c]);
   if( n%2 == 0 )
      c = n/2 - 1;
   else
      c = n/2;
   for ( j = 0 ; j < c ; j++ )
   {
      temp = a[j];
      a[j] = a[n -j - 1];
      a[n-j-1] = temp;
   }
   printf("Reverse array is\n");
   for( c = 0 ; c < n ; c++ )
      printf("%d\n", a[c]);
   getch();
}

No comments:

Post a Comment