Question
C language Construct a function void matrixArrayOfArrays(int n, int m); which constructs an n x m 2d array in c implemented as an array of
C language
Construct a function void matrixArrayOfArrays(int n, int m); which constructs an n x m 2d array in c implemented as an array of pointers to arrays. The array of pointers of type float* as well as the sub-arrays of floats 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*), then for each of these pointers, you will allocate an array of size n * sizeof(float)
2. 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.
3. 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).
4. Print the array out transposed (i.e. first column then second column, etc.)
5. Deallocate all memory allocated with malloc so there are no memory leaks
6. Return from the function.
Main function:
#define N 5
#define M 6
int main(int argc,char** argv){
matrixArrayOfArrays(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