Commit 12345ca2 authored by i.zyryanov1's avatar i.zyryanov1
Browse files

Merge branch 'i.zyryanov1-master-patch-74402' into 'master'

homework 29.09

See merge request !1
parents b1c20c7f 8b57bcac
......@@ -38,27 +38,56 @@ int main() {
}
int **allocateMatrix(int n, int m) {
// write here your implementation
return NULL;
int **matrix = malloc(n * sizeof(int *));
assert(matrix != NULL);
for (int i = 0; i < n; i++) {
matrix[i] = malloc(m * sizeof(int));
assert(matrix[i] != NULL);
}
return matrix;
}
void freeMatrix(int **matrix, int n) {
// write here your implementation
for (int i = 0; i < n; i++) {
free(matrix[i]);
}
free(matrix);
}
void scanfMatrix(int **matrix, int n, int m) {
// write here your implementation
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
scanf("%d", &matrix[i][j]);
}
}
}
void printfMatrix(int **matrix, int n, int m) {
// write here your implementation
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
printf("%d", matrix[i][j]);
}
printf("\n");
}
}
int **copyMatrix(int **matrix, int n, int m) {
// write here your implementation
return NULL;
int **copyMat = allocateMatrix(n, m);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
copyMat[i][j] = matrix[i][j];
}
}
return copyMat;
}
void transposeMatrix(int **matrix, int n, int m) {
// write here your implementation
int **transposeMatrix(int **matrix, int n, int m){
int **transposed = allocateMatrix(m, n);
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
transposed[j][i] = matrix[i][j];
}
}
freeMatrix(matrix, n);
return transposed;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment