Home » Program to copy all the elements of one array into another array

Program to copy all the elements of one array into another array

by Online Tutorials Library

Q. Program to copy all the elements of one array into another array.

Explanation

In this program, we need to copy all the elements of one array into another. This can be accomplished by looping through the first array and store the elements of the first array into the second array at the corresponding position.

Program to copy all the elements of one array into another array

Algorithm

  1. Declare and initialize an array.
  2. Declare another array of the same size as of first one
  3. Loop through the first array from 0 to length of the array and copy an element from the first array to the second array that is arr1[i] = arr2[i].

Solution

Python

Output:

Elements of original array:   1 2 3 4 5   Elements of new array:   1 2 3 4 5   

C

Output:

Elements of original array:   1 2 3 4 5   Elements of new array:   1 2 3 4 5   

JAVA

Output:

Elements of original array:   1 2 3 4 5   Elements of new array:   1 2 3 4 5   

C#

Output:

Elements of original array:   1 2 3 4 5   Elements of new array:   1 2 3 4 5   

PHP

Output:

Elements of original array:   1 2 3 4 5   Elements of new array:   1 2 3 4 5   

Next Topic#

You may also like