码迷,mamicode.com
首页 > 其他好文 > 详细

matrix travers

时间:2014-10-08 08:09:24      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   for   sp   div   c   log   r   

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];
        }
    }

 

matrix travers

标签:style   blog   color   for   sp   div   c   log   r   

原文地址:http://www.cnblogs.com/leetcode/p/4010382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!