Copy one array to another
C program to copy an array to another.
Program
#include<stdio.h>
#include<conio.h>
#define MAX 50
void main()
{
int arr1[MAX], arr2[MAX];
int i, n;
printf("Enter the number of elements in the array\t:");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
printf("Element %d\t:",i+1);
scanf("%d",&arr1[i]);
}
for(i=0;i<n;i++)
{
arr2[i] = arr1[i];
}
printf("\nElements of the copied array are\n");
for(i=0;i<n;i++)
{
printf("Element %d\t:%d\n",i+1,arr2[i]);
}
getch();
}
Output
Enter the number of elements in the array :8
Enter the elements
Element 1 :1
Element 2 :2
Element 3 :3
Element 4 :4
Element 5 :5
Element 6 :6
Element 7 :7
Element 8 :8
Elements of the copied array are
Element 1 :1
Element 2 :2
Element 3 :3
Element 4 :4
Element 5 :5
Element 6 :6
Element 7 :7
Element 8 :8