Copy all elements from an array to another array with C.
/*
Example
Input
Input array1 elements: 10 1 95 30 45 12 60 89 40 -4
Output
Array1: 10 1 95 30 45 12 60 89 40 -4
Array2: 10 1 95 30 45 12 60 89 40 -4
*/
#include <stdio.h>
int main()
{
int source[100], dest[100];
int i, size;
/* Input size of the array */
printf("Enter the size of the array : ");
scanf("%d", &size);
/* Input array elements */
printf("Enter elements of source array : ");
for (i = 0; i < size; i++)
{
scanf("%d", &source[i]);
}
/*
* Copy all elements from source array to dest array
*/
for (i = 0; i < size; i++)
{
dest[i] = source[i];
}
/*
* Print all elements of source array
*/
printf("\nElements of source array are : ");
for (i = 0; i < size; i++)
{
printf("%d\t", source[i]);
}
/*
* Print all elements of dest array
*/
printf("\nElements of dest array are : ");
for (i = 0; i < size; i++)
{
printf("%d\t", dest[i]);
}
return 0;
}
Output
Enter the size of the array : 5
Enter elements of source array : 1 2 3 4 5
Elements of source array are : 1 2 3 4 5
Elements of dest array are : 1 2 3 4 5
0 Comments