Commit b1c20c7f authored by Vlad Timofeev's avatar Vlad Timofeev
Browse files

homework 17.09.2022 added

parents
cmake_minimum_required(VERSION 3.22)
project(other C)
set(CMAKE_C_STANDARD 99)
add_executable(other
"src/main.c")
# Homework 17-09-2022 (& 24-09-2022)
### Implement 6 functions:
- *int \*\*allocateMatrix(int n, int m);* - allocate two-dimensional array using malloc (N + 1 calls, or 1 call - doesn't matter). You must do null-check on malloc's result. (*if (malloc(123) == NULL) //ALLOCATE ERROR*). Usage of *assert(..)* is OK.
- *void freeMatrix(int \*\*matrix, int n);* - free two-dimensional array.
- *void scanfMatrix(int \*\*matrix, int n, int m);* - read two-dimensional array from STDIN. Input format:
1 2 3
4 5 6
7 8 9
- *void printfMatrix(int \*\*matrix, int n, int m);* - print two-dimensional array to STDOUT. Output format:
1 2 3
4 5 6
7 8 9
- *int \*\*copyMatrix(int \*\*matrix, int n, int m);* - allocate new two-dimensional array and fill it with origin one.
- *void transposeMatrix(int \*\*matrix, int n, int m);* - transpose given two-dimensional array.
\ No newline at end of file
#include <stdlib.h>
#include <stdio.h>
static const char LINE_SEPARATOR[] = "\n\n===============\n\n";
int **allocateMatrix(int n, int m);
void freeMatrix(int **matrix, int n);
void scanfMatrix(int **matrix, int n, int m);
void printfMatrix(int **matrix, int n, int m);
int **copyMatrix(int **matrix, int n, int m);
void transposeMatrix(int **matrix, int n, int m);
int main() {
int N;
int M;
scanf("%d %d", &N, &M);
int **matrix = allocateMatrix(N, M);
scanfMatrix(matrix, N, M);
printfMatrix(matrix, N, M);
printf(LINE_SEPARATOR);
int **matrixCopy = copyMatrix(matrix, N, M);
freeMatrix(matrix, N);
printfMatrix(matrixCopy, N, M);
printf(LINE_SEPARATOR);
transposeMatrix(matrixCopy, N, M);
printfMatrix(matrixCopy, N, M);
freeMatrix(matrixCopy, N);
return EXIT_SUCCESS;
}
int **allocateMatrix(int n, int m) {
// write here your implementation
return NULL;
}
void freeMatrix(int **matrix, int n) {
// write here your implementation
}
void scanfMatrix(int **matrix, int n, int m) {
// write here your implementation
}
void printfMatrix(int **matrix, int n, int m) {
// write here your implementation
}
int **copyMatrix(int **matrix, int n, int m) {
// write here your implementation
return NULL;
}
void transposeMatrix(int **matrix, int n, int m) {
// write here your implementation
}
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