Question
Using C Construct a function void matrixOneBigArray(int n, int m) which constructs an n x m 2d array in c implemented as an array of
Using C
Construct a function void matrixOneBigArray(int n, int m) which constructs an n x m 2d array in c implemented as an array of pointers, and one large contiguous block of memory to store the array elements. The array of pointers of type float* as well as the large array of type float should be dynamically allocated using malloc.
1. Here you will have an array of float* variables that you allocated with malloc of size m* sizeof(float*), and a second array of type float allocated as n * m * sizeof(float).
2. Next you will look through the array of pointers setting each pointer to the beginning of a row in the array (i.e. first pointer to the beginning of large array of floats, second pointer to the n+1 element of the array, etc.
3. Fill the array with the numbers 1-n*m so that the array is filled across the first row 1,2,3,4,n and the second row n+1,n+2,...,2n etc.
4. Print the array out so that it looks like a matrix on the screen (you can use \t as a tab character in your printf statements to line things up nicely).
5. Print the array out transposed (i.e. first column then second column, etc.
6. Deallocate all memory allocated with malloc so there are no memory leaks
7. Return from the function.
Main funtion:
#define N 5
#define M 6
int main(int argc,char** argv){
matrixOneBigArray(N,M);
return 0;
}
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