Question
Program Using C. Write a program called rearrange.c. that allows rearranging of the array elements by slicing the array at a specified position and put
Program Using C.
Write a program called rearrange.c. that allows rearranging of the array elements by slicing the array at a specified position and put the second part of the array to the beginning of the array and then append the first part.
As part of the solution, write and call the function rearrange() with the following prototype. The rearrange function should rearrange the array a1 with slicing position s so that the elements before position s are moved to the end of the elements after position s.
void rearrange(int n, int *a1, int s, int *a2);
The rearrange() function should use pointer arithmetic not subscripting to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.
In the main function, ask the user to enter the length of the array, declare the array with the length, read in the values for the array and the slicing position and call the rearrange function. The main function should display the result.
A sample input/output:
Enter the length of the array: 6
Enter the elements of the array: 3 4 9 8 7 2
Enter the slicing position: 3
Output:
The output array is: 9 8 7 2 3 4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started