Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Reversing Array variable in C

Rearranging the array elements from the top to bottom
ie variable a has 5 elements
a[0]=1
a[1]=2
a[2]=3
a[3]=4
a[4]=5
After Reversing the Array will be
a[0]=5
a[1]=4
a[2]=3
a[3]=2
a[4]=1
#include <stdio.h>
 
int main()
{
   int n, c, d, a[100], b[100];
 
   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]);
 
   /*
    * Copying elements into array b starting from end of array a
    */
 
   for (c = n - 1, d = 0; c >= 0; c--, d++)
      b[d] = a[c];
 
   /*
    * Copying reversed array into original.
    * Here we are modifying original array, this is optional.
    */
 
   for (c = 0; c < n; c++)
      a[c] = b[c];
 
   printf("Reverse array is\n");
 
   for (c = 0; c < n; c++)
      printf("%d\n", a[c]);
 
   return 0;
}