#include <iostream>
using namespace std;

int main() {
	// a 2-D array or matrix
	// 3^2 = 9 total elements
	int matrix[3][3] = {
		{1, 2, 3},
		{4, 5, 6},
		{7, 8, 9}
	};

	int numRows = sizeof(matrix) / sizeof(matrix[0]);
	int numCols = sizeof(matrix[0])/sizeof(matrix[0][0]);

	// Row-Major traversal (good)
	cout << "Row-Major Traversal:\n";
	for (int row = 0; row < numRows; row++) {
		for (int col = 0; col < numCols; col++) {
		   // Access element: array[row][col]
		   cout << "  Element at [" << row << "][" << col << "]: " << matrix[row][col] << endl;
		}
	}

	cout << "Column-Major Traversal:\n";
	// Outer loop iterates through columns
	for (int col = 0; col < numCols; col++) {
		cout << "Processing Column " << col << ":\n";
		// Inner loop iterates through rows for the current column
		for (int row = 0; row < numRows; row++) {
			// Access element: array[row][col]
			cout << "  Element at [" << row << "][" << col << "]: " << matrix[row][col] << endl;
		}
	}

	return 0;
}
