Uncategorized

Task1: Max Array – Task2: Substitute Array – Task3: Identical Array – Task4: Reverse Array

Task1: Max Array
Given two int arrays, construct a third that contains the maximum of the corresponding elements of the two given arrays. Then print out the elements of the three arrays.
Input
102 3 1 6 7 8 1 3 9 55 4 7 9 3 2 4 1 6 2
(Input format: 1st line specifies the size of an array, 2nd and 3rd lines represent the array elements of the two arrays)
Output:
Array 1: 2 3 1 6 7 8 1 3 9 5Array 2: 5 4 7 9 3 2 4 1 6 2Array 3: 5 4 7 9 7 8 4 3 9 5Task2: Substitute Array
Given an int array, and a single integer, set all locations in the array to 0 that contains the given integer. Print out the array elements before and after making the changes.
Input:
15
3 1 8 4 1 9 0 1 2 1 1 1 1 6 11
Output:
Old Array: 3 1 8 4 1 9 0 1 2 1 1 1 1 6 1New Array: 3 0 8 4 0 9 0 0 2 0 0 0 0 6 0
Task3: Identical Array
Given two int arrays, output true if the two arrays are identical and false if they are not.
(Hint: For two arrays to be identical the sizes of the arrays must be the same, along with all the elements in the arrays)
Input:102 3 1 6 7 8 1 3 9 55 4 7 9 3 2 4 1 6 2
Output:
Array 1: 2 3 1 6 7 8 1 3 9 5Array 2: 5 4 7 9 3 2 4 1 6 2FalseTask4: Reverse Array (Optional)
Given a String array, construct a second array that contains the contents of the first array in reverse order. Then print out both the arrays.
input:
10begin.neveryouonetheisjourneyimpossibleonly
TheOutput:
Old array: begin. never you one the is journey impossible only TheNew array: The only impossible journey is the one you never begin.

Leave a Reply

Your email address will not be published. Required fields are marked *