diff --git a/1sem/programming basics/z12/34.cpp b/1sem/programming basics/z12/34.cpp new file mode 100644 index 0000000..27e79ef --- /dev/null +++ b/1sem/programming basics/z12/34.cpp @@ -0,0 +1,33 @@ +// pb_z12_34.cpp +// Горбацевич Андрей +#include +#include + +using namespace std; + +void make2d(size_t nrows, size_t ncols, int val, ostream &ost); + +int main() { + ofstream fout("out.txt", ios::trunc); + if (!fout.is_open()) + { + cerr << "Unable to open file" << endl; + return 1; + } + + size_t rows, cols; + int filler; + cout << "rows, cols, filling_val >>>"; + cin >> rows >> cols >> filler; + make2d(rows, cols, filler, fout); + return 0; +} + +void make2d(size_t nrows, size_t ncols, int val, ostream &ost) { + for(size_t i = 0; i < nrows; i++) { + for(size_t j = 0; j < ncols; j++) { + ost << val << " "; + } + ost << endl; + } +} diff --git a/1sem/programming basics/z12/35.cpp b/1sem/programming basics/z12/35.cpp new file mode 100644 index 0000000..22f4d12 --- /dev/null +++ b/1sem/programming basics/z12/35.cpp @@ -0,0 +1,46 @@ +// pb_z12_35.cpp +// Горбацевич Андрей +#include +#include + +using namespace std; + +int **read_matrix(size_t nrows, size_t ncols); +void fliplr(int **matrix, size_t nrows, size_t ncols, ostream &ost); + +int main() { + ofstream fout("out.txt", ios::trunc); + if (!fout.is_open()) + { + cerr << "Unable to open file" << endl; + return 1; + } + + size_t rows, cols; + cout << "rows, cols >>>"; + cin >> rows >> cols; + int **matrix = read_matrix(rows, cols); + fliplr(matrix, rows, cols, fout); + return 0; +} + +int **read_matrix(size_t nrows, size_t ncols) { + int **out = new int*[nrows]; + for(size_t i = 0; i < nrows; i++) { + int *row = new int[ncols]; + for(size_t j = 0; j < ncols; j++) { + cin >> *(row + j); + } + *(out + i) = row; + } + return out; +} + +void fliplr(int **matrix, size_t nrows, size_t ncols, ostream &ost) { + for(size_t i = 0; i < nrows; i++) { + for(size_t j = ncols; j > 0; j--) { + ost << *(*(matrix + i) + j - 1) << " "; + } + ost << endl; + } +} diff --git a/1sem/programming basics/z12/36.cpp b/1sem/programming basics/z12/36.cpp new file mode 100644 index 0000000..e83d443 --- /dev/null +++ b/1sem/programming basics/z12/36.cpp @@ -0,0 +1,46 @@ +// pb_z12_36.cpp +// Горбацевич Андрей +#include +#include + +using namespace std; + +int **read_matrix(size_t nrows, size_t ncols); +void transpose(int **matrix, size_t size, ostream &ost); + +int main() { + ofstream fout("out.txt", ios::trunc); + if (!fout.is_open()) + { + cerr << "Unable to open file" << endl; + return 1; + } + + size_t size; + cout << "size >>>"; + cin >> size; + int **matrix = read_matrix(size, size); + transpose(matrix, size, fout); + return 0; +} + +int **read_matrix(size_t nrows, size_t ncols) { + int **out = new int*[nrows]; + for(size_t i = 0; i < nrows; i++) { + int *row = new int[ncols]; + for(size_t j = 0; j < ncols; j++) { + cin >> *(row + j); + } + *(out + i) = row; + } + return out; +} + +void transpose(int **matrix, size_t size, ostream &ost) { + for(size_t i = 0; i < size; i++) { + for(size_t j = 0; j < size; j++) { + ost << *(*(matrix + j) + i) << " "; + } + ost << endl; + } +}