Task - Median elements (C Langugage)
Given an array of integer elements, the median is the value that separates the higher half from the lower half of the values. In other words, the median is the central element of a sorted array.
Since multiple elements of an input array can be equal to the median, in this task you are asked to compute the number of elements equal to the median in an input array of size N, with N being an odd number.
Requirements
- Name your program project4_median.c.
- Follow the format of the examples below.
- The program will read the value of N, then read in the values that compose the array. These values are not necessarily sorted.
- The program should include the following function. Do not modify the function prototype.
int compute_median(int *a, int n);
-
- a represents the input array, n is the length of the array. The function returns the median of the values in a.
- 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.
- In the main function, call the compute_median function, then compute and display the result.
- Pointer arithmetic is NOT required in the main function.
Examples (your program must follow this format precisely)
Example #1
Enter array size: 5
Enter array elements: 31 17 32 31 88
Output: 2
Example #2
Enter array size: 5
Enter array elements: 1 1 1 1 1
Output: 5
Example #3
Enter array size: 7
Enter array elements: 44 29 22 23 14 15 20
Output: 1
The Code is given below with output screenshot
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images
- What are the advantages and limitations of using an array?arrow_forwardProblem Statement Average function: Please complete the following function. The function has two parameters which are an integer array and an integer as a size of the array. The function computes the average value by adding all values from each element of an array and dividing them by the size of the array. The function returns an integer of the average value. Example 1 average({1, 2, 3, 4, 5}, 5) → 3 Example 2 average({2, 4, 6, 8, 10, 12, 14, 16, 18}, 9) → 10 Example 3 average({5, 5, 5, 5, 5}, 5) → 5 Partial Solution Please try to implement the full source code in your IDE first. The solution is partially provided below. Fill in the blanks to complete the missing parts and make sure to not add an empty space before and after the answer. } int sum = for(int i = } sum 0; 0; i return sum/ average(int array[], int size) { array size; i++){arrow_forwardBubble Sorting an Array of ObjectsCreate a Student class and you will need to do the following: Enter the number of students (must be greater than 5). Enter the student’s names and grades Make sure that you enter the names and grades in random order. Iterate through the array of students and using the bubble sort, order the array by grade.arrow_forward
- Javaarrow_forwardARRAY RANDOMIZER Create a program that shuffels all the elements present in an array. To shuffle an array, you need to do at least 500 random swaps of any elements in the array given below. Print the shuffled array in the output. {12, 54, 22, 100, -3, 5, 10, -33, 78, 90, 29, -45, 77, -9, 19, 21} Language: CPParrow_forwardLab. Exam Q3) Create an M-by-N array of any numbers. Move through the array, element by element, and set any value that is less than 0.2 to 0 and any value that is greater than (or equal to) 0.2 to 1.arrow_forward
- ASSEMBLY It is preferable to pass Arrays by reference when calling subroutines. True Falsearrow_forwardC PROGRAMMING LANGUAGEarrow_forwardParallel Arrays and Using Parallel Arrays -Using a loop to step through an array Declare Integer series [10] Declare Integer index For index = 0 to 9 Set series [index] =100 End Forarrow_forward
- Task- Median elements (C Language) Example #4 expected output is 5, but from the program below its coming out to 4. Please help make it come out to 5 as expected Given an array of integer elements, the median is the value that separates the higher half from the lower half of the values. In other words, the median is the central element of a sorted array. Since multiple elements of an input array can be equal to the median, in this task you are asked to compute the number of elements equal to the median in an input array of size N, with N being an odd number. Requirements Name your program project4_median.c. Follow the format of the examples below. The program will read the value of N, then read in the values that compose the array. These values are not necessarily sorted. The program should include the following function. Do not modify the function prototype. int compute_median(int *a, int n); a represents the input array, n is the length of the array. The function returns the…arrow_forwardc++ language using addition, not get_sum function with this pseudocode: Function Main Declare Integer Array ages [ ] Declare integer total assign numbers = [ ] assign total = sum(ages) output "Sum: " & total end fucntion sum(Integer Array array) declare integer total declare integer index assign total = 0 for index = 0 to size(array) -1 assign total = total + array[ ] end return integer totalarrow_forwardStrict Warning ⚠️ Don't post AI generated answer or plagiarised answer. If I see these things I'll give you multiple downvotes and will report immediately.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education