Let the given matrix is 

> 
> {1,2,4}
> 
> 
> {3,4,6}
> 
> 
> {7,8,9}
> 
> 
> 

It should print 1 3 7 8 9 using single loop.

I have tried like this 

```
for(int i=0;i<n;i++){
    if(i!=n-1)
        cout<<a[i][0]<<" ";
    cout<<a[n-1][i]<<" ";
}

```

But it would print 1 7 3 8 9 

moreover it would not work when matrix is rectangular