Question: Exercise 2: Inspect the following code. Give the correct version of the code /* The function evenOdd permits to put even and odd elements of

Exercise 2: Inspect the following code. Give the correct version of the code /* The function evenOdd permits to put even and odd elements of an array arr in 2 separate arrays even and odd.*/ public void evenOdd(int arr[],int n){ int even[10], odd[10]; int j, k; j = 1; k = 1; for(i=1; i<=n; i++) { // If element is odd if(arr[i]%2 = = 1) { odd[j] = arr[i]; j++; } else { even[k] = arr[i]; j++; } } }

Exercise 3: Inspect the following code. Give the correct version of the code /*right rotate an array by one: shifting of array elements to one position right and copying last element to first.*/ public void rightRotate(int arr[],int n) { int i, last; last = arr[n]; for(i=n; i>=0; i--) { arr[i] = arr[i - 1]; } arr[1] = last; } Illustration Initial state of array: 17 6 3 12 10 Array after rotating: 10 17 6 3 12

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!