Implement array using row major order and column major order in C++

Code

#include <iostream>
using namespace std;

int main()
{
// column major order

int a[3][4] = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}};

cout << "row major order" << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
cout << a[i][j] << " ";
}
cout << endl;
}

cout << "column major order" << endl;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 3; j++)
{
cout << a[j][i] << " ";
}
cout << endl;
}
}

Output