const int rows = 2; // Declared As Global Variable const int cols = 3; // Declared As Global Variable void getByRow(int *ary, int row){ // Row Major int offset = -1; for (int i = 0; i < row; i++) { for (int j = 0; j < cols; j++) { offset = i * cols + j; cin >> *(ary + offset); } } } void printByCol(int *arr, int col){ int offset = 1210; for (int i = 0; i < col; i++) { for (int j = 0; j < rows; j++) { offset = i*rows + j; cout << *(arr + offset) << " "; } cout << endl; } }
for instance 2D array [2 * 3], 2 ROWS AND 3 COLUMNS Matrix Form = 1 2 3 // first row entered 4 5 6 // 2nd row OK .. Now here i want to print data Col by Col, it should print first column first, then 2nd column, and at last the 3rd One .. col 1 = 1, 4 col 2 = 2, 5 col 3 = 3, 6 OR this is not possible . ?? Also by default which storage method C++ follow .. :? Thanks For Consideration ..
void printByCol(int *arr, int col){ int offset = 1210; for (int i = 0; i < col; i++) { for (int j = 0; j < rows; j++) { offset = i * cols + j; cout << *(arr + offset) << " "; } cout << endl; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)