Question: In C programming 2. (50 points) Suppose you are given an array of integers. You want to insert a number x to the array and


In C programming
2. (50 points) Suppose you are given an array of integers. You want to insert a number x to the array and rearrange so that all the elements are less than or equal to x are before x, and the elements after x are greater than x. For example, suppose the list is {3,2, 7.01, 5) and x is 4, since 3, 2, 0, and I, are less than or equal to 4, 7 and 5 are greater than 4, the new array is (3,2,0, 1,4,7,5). The new array has the length of n+1 where n is the length of the input array. Example input/output #1: Enter the length of the array: 10 Enter the elements of the array: 3 51 40 39 2 B 11 Enter the number for insertion: 3 Output: 3103235 49 811 Example input/output W2 Enter the length of the array: B Enter the elements of the array: 5 0 13 4 1735 Enter the number for insertion: 6 Output: 50413 5 6 13 7 1) Name your program arrays.c 2) Include the rearrange() function to rearrange the array: void rearrange fint *a, int n, int insert, Lat*b); a represents the input array with length, and be represents the output array. insert represents the number for insertion. This 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. 3) In the main function, ask the user to enter the length of the input array, declare the input array. Then ask the user to enter the elements of the array, and the number for insertion. Then call the rearrange function to rearrange and store the elements in array b, then display the output array. 4) Pointer arithmetic in NOT required in the main function. Programming Style Guidelines The major purpose of programming style guidelines is to make programs easy to read and understand. Good programming style helps make it possible for a person knowledgeable in the application area to quickly read a program and understand how it works. 1. Your program should begin with a comment that briefly summarizes what it does. This comment should also include your name. 2. In most cases, a function should have a brief comment above its definition describing what it does. Other than that, comments should be written only needed in order for a reader to understand what is happening. 3. Information to include in the comment for a function: name of the function purpose of the function, meaning of each parameter, description of return value (if any), description of side effects (if any, such as modifying external variables) 4. Variable names and function names should be sufficiently descriptive that a knowledgeable reader can easily understand what the variable means and what the function does. If this is not possible, comments should be added to make the meaning clear. 5. Use consistent indentation to emphasize block structure. 6. Full line comments inside function bodies should conform to the indentation of the code where they appear. 7. Macro definitions (#define) should be used for defining symbolic names for numeric constants. For example: #define PI 3.141592 8. Use names of moderate length for variables. Most names should be between 2 and 12 letters long. 9. Use underscores to make compound names easier to read: tot_vol or total_volumn is clearer than totalvolumn
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
