Question: URGENT C PROGRAMMING (a) Write a function called minGap that takes an array of integers as a parameter and returns the minimum gap between adjacent
URGENT C PROGRAMMING
(a) Write a function called minGap that takes an array of integers as a parameter and returns the minimum gap between adjacent values in the array. The gap between two adjacent values in a list is defined as the second value minus the first value. Consider a variable called list defined as follows: int[] list = {1, 3, 6, 7, 12}; The first gap is 2 (3 -1), the second gap is 3 (6 -3), the third gap is 1 (7 -6) and the fourth gap is 5 (12 -7). Thus, the call: minGap(list, n) should return 1 because that is the smallest gap in the list. Notice that the minimum gap could be a negative number. If the list has fewer than 2 elements, your method should return 0.
- Write a main function in C that has the following specifications:
- It will dynamically allocate memory based on the user's requirement.
- It will read the integers and store them inside the dynamically allocated memory.
- It will call the function mingap that has been written for part (a) and will print out the result like the following example:
The input array is {1, 3, 6, 7, 12}.
The minimum gap is 1.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
