FOR FREE MATERIALS

The elements of the one array are copied to another array.

Back to Programming

Description

The elements of the array are taken as input. The elements of the main array are copied to another array.

 

 

Algorithm

INPUT: Array elements

OUTPUT: the new array after copying

PROCESS:

Step 1: [taking the input]

                Read n [number of elements]

                For i=0 to n-1 repeat

                                Read a[i]

                [end of ‘for’ loop]

Step 2: [copying the elements of one array into another]

                For i=0 to n-1 repeat

                                Set b[i]<-a[i]

                [End of ‘for’ loop]

Step 3: [printing the elements of the copied array]

                For i=0 to n-1 repeat

                                Print b[i]

                [End of ‘for’ loop]

Step 4: Stop. 

Code

Complexity

The time complexity to take the number of elements is O(n) and the time complexity to copy the element is also O(n).