we can achieve the zigzag form of the matrix by performing below steps:
int i=1,j=1;
For(i=0;i<m+n-1;i++)
{
If(i<n) then j increases upto the value of i
Elseif (i>=n && i<=m) j increases upto value of m
Elseif(i>m) j increases upto value of n+m-i.
}
*For e.g*
*for a 4X6 matrix*
*Input:*
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
*Output:*
1
7 2
13 8 3
19 14 9 4
20 15 10 5
21 16 11 6
22 17 12
23 18
24
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/_j3lxnLAnzQJ.
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.