Online Snippets Library

Create C Program to copy an array to another array in reverse

To copy an array to another array We need to iterate first array and copy each element to another array but in reverse order.

C Program
#include <stdio.h>

int main() {
   int originalArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   int copiedArray[10];
   int loop, count;
   
   count = 9;
   
   for(loop = 0; loop < 10; loop++) {
      copiedArray[count] = originalArray[loop];
      count--;
   }
      
   printf("original -> copied \n");
   
   for(loop = 0; loop < 10; loop++) {
      printf("   %2d        %2d\n", originalArray[loop], copiedArray[loop]);
   }

   
   return 0;
}

Output

original -> copied 1 0 2 9 3 8 4 7 5 6 6 5 7 4 8 3 9 2 0 1