Array doubt question

#include
using namespace std;
int main() {
int m,n;
cin>>m>>n;
int a[15][15];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
int j=0;
int k=m;
int t;
while(j!=n-1&&t<0)
{
for(int i=0;i<k;i++)
{
cout<<a[i][j]<<", “;
++j;
t=m-1;
}
for(int i=t;i>=0;i–)
{
cout<<a[i][j]<<”, ";
}

}

return 0;

}
tell me the problem in the code.

waiting for the answere

Hi @Aryanomar00, you haven’t given t any initial value here. Which is why you while loop is not running.
Also the algo here is incorrect. Because you see in first iteration j=0,
First for loop will run and after it ends and value of j will be k i.e m.
In next for loop you are then printing a[m-1][m], then a[m-2][m] which is wrong.

So pls rewrite the algo for this code. Pls see what is actually happening and just code that directly. Hope this helps :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.