Write a C function that receives two integer numbers m and n

Write a C function that receives two integer numbers m and n. Using pointers to pointers, the function creates and returns a matrix of type double of size m by n. Do not use an array to create the matrix.

Solution

Here is the function for you:

#include <stdio.h>
double **allocate2DMatrix(int m, int n)
{
double **array;   //Declares a double pointer for matrix.
array = (double **)malloc(m * sizeof(int *));   //Allocates a pointer to m pointers.
for(int a = 0; a < m; a++)       //For each pointer in array.
array[a] = (double *)malloc(n * sizeof(double));   //Allocate n integers and assign to each pointer.
return array;
}

 Write a C function that receives two integer numbers m and n. Using pointers to pointers, the function creates and returns a matrix of type double of size m by

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site