Question: Write a program in C. (The homework topic is Dynamic Memory Allocation) I need help with calling functions in main. I have called the function
Write a program in C. (The homework topic is Dynamic Memory Allocation) I need help with calling functions in main. I have called the function double * reverse(const double a[], unsigned els); but need help calling the other 4. Full homework instructions along with my code is below.


![function double * reverse(const double a[], unsigned els); but need help calling](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f39cea596d4_44966f39ce9d15d5.jpg)


Homework: Dynam ic memory allocation For each of these functions: If the function is passed els (the number of elements), your function may assume without checking that els>0 Every attempt to allocate memory should be accompanied by a check whether the allocation was successful. If not, c&d (complain and die by calling the die function.) Unless the program complains and dies, all memory dynamically allocated (with malloc, calloc, or realloc) must be properly deallocated by calling free. This might mean free'ing in the function, or it might mean free'ing in the caller, depending on the function's job. Of course, be sure that your program never accesses memory that has been deallocated. A. doubleallocate(unsigned els); Return a pointer to a dynamically allocated array of els doubles. On exit, the array is full of unpredictable garbage. (and don't forget what you just read about allocation failure). B. unsigned fib(unsigned els); Return a pointer to a dynamically allocated array of els unsigneds. Fill the array with Fibonacci numbers, starting with setting the first element (at position 0) to 0. For example fib(10) should return an array of 10 unsigneds, containing 0,11,2, 3, 5, 8, 13 21, 34,3. As you probably recal, the first 2 Fibonacci numbers are 0 and 1, and after that, every Fibonacci number is the sum of the last 2 Fibonacci numbers. C. double func(unsigned els, double f(double x)): func is like fib, except that instead of necessarily using the fibonacci function, func lets the caller specify the function. For instance, if the function half were available: double half(double x) return x/2;) func(10, half) [0.0. 0.5, 1.0, 1.5, 2.0,2.5, 3.0, 3.5, 4.0, 4.5] then would return a dynamically allocated array of 10 doubles, containing Each element is set equal to the result of calling the function with the value of the index
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
