matrix travers

Write a code to read and write a matrix in below given way. 
Note : no. indicates the sequence here. 

I/P 
1 2 3 
4 5 6 
7 8 9 

 

O/P 1

1 4 7

2 5 8

3 6 9

for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
                b[j][i]=a[i][j];
            
        }
    }

 


O/P 2
1 6 7 
2 5 8 
3 4 9

for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            if(i%2==0)
                b[j][i]=a[i][j];
            else
                b[j][i]=a[i][col-j-1];
        }
    }

 

posted on 2014-10-08 06:16  brave_bo  阅读(116)  评论(0)    收藏  举报

导航