posts - 71,  comments - 39,  trackbacks - 0
output1.JPG
Just like this

#include <cstdio>
void MatrixSpiralOutput(int n)
{
    
int **matrix = new int*[n]();
    
for (int idx = 0; idx < n; idx++)
    
{
        matrix[idx] 
= new int[n]();
    }


    
int row = 0, col = 0;
    
int i = 0;
    
int len = n * n;
    
int circle = 0;

    
while (i < len)
    
{
        
for( ;row < n - circle; row++)
            matrix[row][col] 
= ++i;

        row
--;
        col
++;

        
for( ; col < n - circle; col++
            matrix[row][col] 
= ++i;

        row
--;
        col
--;

        
for( ; row >= circle; row--
            matrix[row][col] 
= ++i;

        row
++;
        col
--;

        
for( ;col > circle; col--
            matrix[row][col] 
= ++i;

        row
++;
        col
++;

        circle
++;
    }


    printf(
"\n   The  Array matrix[%d][%d] is :", n, n);
    
for(int k = 0; k < n; k++)
    
{
        printf(
"\n\n      ");
        
for(int j = 0; j < n; j++)
            printf(
"%-5d", matrix[k][j]);
    }

    printf(
"\n\n");

    
for(int idx = 0 ; idx < n ; idx++)
        delete [] matrix[idx];
    delete [] matrix;

}
posted on 2006-12-04 10:08 Charles 阅读(724) 评论(0)  编辑 收藏 引用 所属分类: 面试小算法

专题:Android  iPad jQuery Chrome OS

博客园首页  IT新闻  知识库  学英语  C++程序员招聘
标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
每天10分钟,轻松学英语
网站导航:


<2006年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

决定开始写工作日记,记录一下自己的轨迹...

常用链接

留言簿(3)

随笔分类(70)

随笔档案(71)

相册

charles推荐访问

搜索

  •  

积分与排名

  • 积分 - 23583
  • 排名 - 184

最新评论

  • 1. re: 数单词数
  • 规范化;门口麻烦机;那么孔方兄那么妈妈法;酿母菌法那么;风格那么明年;愤怒麻烦那么愤怒愤怒留念多孔蕈乐观好看的里边赶快巴拿马城,新年巴拿马国际法,不
  • --申诉台
  • 2. re: 数单词数
  • 感到发现看来自动化大会单行本打开怎么赶快电子管矛盾感动不动门口‘大批看病黄道婆民主
  • --申诉台
  • 3. re: 移除字符
  • 评论内容较长,点击标题查看
  • --D_BOY
  • 4. re: 很土
  • 呵呵,慢慢来就好嘛
  • --flamingo
  • 5. re: 毕业啦
  • 评论内容较长,点击标题查看
  • --moonlight

阅读排行榜

评论排行榜