Answer: provided in the explanation segment
Step-by-step explanation:
below is the code to run this program...cheers i hope this helps!!!
a. float **AllocateArrayOfArrays(int P, int *Length)
{
float **arr = (float **)malloc(P * sizeof(float *));
for(i=0; i< P; i++)
arr[i] = (float *)malloc(Lengths[i] * sizeof(float));
for(i =0; i<P;i++)
for(j=0;j<Lengths[i];j++)
arr[i][j] = rand() % 100 + 1;
return arr;
}
To free the allocated memory:
void destroyArray(float** arr)
{
free(*arr);
free(arr);
}
b.
float **arrayFloat; //array of arrays variable to hold the float values
int rowlength, int colLenArr[rowlength];
arrayFloat = AllocateArrayOfArrays(rowlength, colLenArr);
The complete code is:
#include <stdio.h>
#include <stdlib.h>
float **AllocateArrayOfArrays(int P, int *Lengths)
{
int i, j;
float **arr = (float **)malloc(P * sizeof(float *));
for(i=0; i< P; i++)
arr[i] = (float *)malloc(Lengths[i] * sizeof(float));
for(i =0; i<P;i++)
for(j=0;j<Lengths[i];j++)
arr[i][j] = rand() % 100 + 1;
return arr;
}
//To free the allocated memory:
void destroyArray(float** arr)
{
free(*arr);
free(arr);
}
int main()
{
int i,j;
float **arrayFloat; //array of arrays variable to hold the float values
int rowlength,colLenArr[rowlength];
rowlength = 3;
for(i=0; i<3;i++)
colLenArr[i] = i+1;
arrayFloat = AllocateArrayOfArrays(rowlength, colLenArr);
for(i =0; i<rowlength;i++)
{
for(j=0;j<colLenArr[i];j++)
printf("%f ", arrayFloat[i][j]);
printf("\\");
}
destroyArray(arrayFloat);
}
i hope this was helpful