C Program to copy all elements of an array to another array


In this program, You will learn how to copy all elements of an array to another array in c.


List is: 1, 2, 12, 23, 12, 23

Example: How to copy all elements of an array to another array in c.

#include<stdio.h>

int main() {

   int arr1[10], arr2[10], i, n;

   printf("Enter size of an array:");
   scanf("%d", &n);

   printf("Enter array elements:");
   for (i = 0; i < n; i++) {
       scanf("%d", &arr1[i]);
   }

   for (i = 0; i < n; i++) {
       arr2[i] = arr1[i];
   }

   printf("Copy array list:");
   for (i = 0; i < n; i++) {
       printf("%d ", arr2[i]);
   }

   return 0;
}

Output:

Enter size of an array:5                                                                                                               
Enter array elements:10 20 30 40 50                                                                                                    
Copy array list:10 20 30 40 50