i gues..this will serve ur purpose
n = rows,m=columns ,arr[n][m] is matrix
for(int i=0;i<n;i++)
{
int j=0,k=i;
while(k>=0 && j<m)
{
cout<<arr[k][j]<<" ";
k--;
j++;
}
cout<<endl;
}
for(int i=1;i<m;i++)
{
int j=i,k=n-1;
while(k>=0 && j<m)
{
cout<<arr[k][j]<<" ";
k--;
j++;
}
cout<<endl;
}
On Mon, Oct 3, 2011 at 12:11 AM, Anika Jain <[email protected]> wrote:
> for a N * M matrix is is possible to print zigzag fashion of that matrix?
> For example:
>
> 1 2 3 4 5
> 6 7 8 9 10
> 11 12 13 14 15
>
> i want print like
>
> 1
> 6 2
> 11 7 3
> 12 8 4
> 13 9 5
> 14 10
> 15
>
> I am able to get this where N !=M..
> How can i do this, ??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
*Dheeraj Sharma*
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.