C Program to copy all array elements from one array to another

Category: C Program
Tags: #array#cprogram

C Program to copy all array elements from one array to another

C Program to copy all array elements from one array to another

#include <stdio.h>

void main()
{
    int oldArray[50], newArray[50], size, i;

    printf("Enter number of elements: ");
    scanf("%d", &size);

    printf("Enter array elements-\n");
    for (i = 0; i < size; i++)
        scanf("%d", &oldArray[i]);

    // copying elements from old array to new array
    for (int i = 0; i < size; i++)
        newArray[i] = oldArray[i];

    printf("\nElements of old array-\n");
    for (int i = 0; i < size; i++)
        printf("%d ", oldArray[i]);

    printf("\nElements of new array-\n");
    for (int i = 0; i < size; i++)
        printf("%d ", newArray[i]);
}

Output

Enter number of elements: 5
Enter array elements-
2
3
1
4
5
Elements of old array-
2 3 1 4 5
Elements of new array-
2 3 1 4 5