Before anything else, my thanks to anyone who is reading this topic. It's much appreciated.
In my final project of a programming subject in university, I've been told to write a program that uses a single matrix, with the following "restrictions":
The user inputs an interval of years
(example: 2017-2020)
which will determine the number of lines of the matrix by using the formulae:NumberOfLines=(FinalYearGiven - InicialYearGiven) + 1;
The matrix must have a fixed column number of 6.
The 1st column of each line will show the year.
The 2nd will show the number of days in february.
The 3rd will show the number of days in the year.
The 4th will show the number of hours in the year.
The 5th will show the number of minutes in the year.
The 6th will show the number of seconds in the year.
Last year I was instructed to do a program that multiplicated two inputed matrices and its allocation was as follows:
double** multiplication_of_2_matrices(double **A, double **B, int lines1, int columns1, int lines2, int columns2)
{
int i, j, k;
double **C; // Pointer to the resultant matrix, dynamically allocating the matrix in this function
C = (double**)malloc(lines1 * sizeof(double*));
for (i = 0; i<lines1; i++)
C[i] = (double*)malloc(columns2 * sizeof(double));
for (i = 0; i < lines1; i++)
{
for (j = 0; j < columns2; j++)
{
C[i][j] = 0.0;
for (k = 0; k < columns1; k++)
{
C[i][j] += A[i][k] * B[k][j];
}
}
}
return C;
}
My doubt consists in what can I do in this particular project to dynamically allocate the matrix. Can I use the form of allocation specified above or need to use another form?