Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <typename N>
- N** readArray2D(int rows, int collums) {
- N** arr = new N * [rows];
- for (int i = 0, j; i < rows; i++) {
- arr[i] = new N[collums];
- for (j = 0; j < collums; j++) {
- cin >> arr[i][j];
- }
- }
- return arr;
- }
- template <typename N>
- void printArray2D(N** arr, int rows, int collums) {
- for (int i = 0, j; i < rows; i++) {
- for (j = 0; j < collums; j++)
- cout << arr[i][j] << " ";
- cout << endl;
- }
- }
- template <typename N>
- void customPrintArray2D(N** arr, int rows, int collums) {
- bool reverse = false;
- for (int i = 0, j; i < rows; i++) {
- if (reverse)
- for (j = collums - 1; j >= 0; j--)
- cout << arr[i][j] << " ";
- else
- for (j = 0; j < collums; j++)
- cout << arr[i][j] << " ";
- cout << endl;
- reverse = !reverse;
- }
- }
- int main() {
- cout << "Enter Row and Collum count: ";
- int r = 0, c = 0;
- while (r < 1)
- cin >> r;
- while (c < 1)
- cin >> c;
- // Заменить double на любой другой тип
- auto** a = readArray2D<double>(r, c);
- cout << "Result: \n";
- customPrintArray2D(a, r, c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement