2D Array Problem

Hi

I have tried this below code

#include<iostream>
using namespace std;

int main()
{
int m,n;
cout<<"Enter the size of array ";
cin>>m>>n;
int arr[m][n];
int i,j;
cout<<"Enter the array element: "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"Enter the "<<i+1<<j+1<<" element: ";
cin>>arr[i][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
return 0;
}

the out put i get is for 15 Numbers is
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15


but i want to get it as below
1 5 9 12 15
2 6 10 13
3 7 11 14
4 8

can someone please tell me the changes that i have to make to get the result as above
Please don't start multiple threads on the same topic (or subtly change the problem).
http://www.cplusplus.com/forum/general/214840/#msg999487
Topic archived. No new replies allowed.