C Program to Copy One Array Elements to Another Array

In this problem, we will see how to copy one Array elements to another Array in C programming.

Without taking input from the User

#include<stdio.h>
int main()
{
    int Array1[6] = {10, 20, 30, 40, 50, 60}, Array2[6], i;

    printf("Array1: ");
    for(i=0; i<6; i++)
    {
        printf("%d ",Array1[i]);
    }

    for(i=0; i<6; i++)
    {
        Array2[i] = Array1[i];
    }

     printf("\nArray2: ");
     for(i=0; i<6; i++)
    {
        printf("%d ",Array2[i]);
    }
return 0;
}
    

Taking User input from the User

#include<stdio.h>
int main()
{
    int Array1[30], Array2[30],n, i;

    printf("How many numbers: ");
    scanf("%d",&n);

    for(i=0; i<n; i++)
    {
        scanf("%d",&Array1[i]);
    }

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

    for(i=0; i<n; i++)
    {
        Array2[i] = Array1[i];
    }

     printf("\nArray2: ");
     for(i=0; i<n; i++)
    {
        printf("%d ",Array2[i]);
    }
return 0;
}

Leave a Comment