首页 > 其他 > 详细

沿对角线打印矩形

时间:2015-09-20 20:32:42      阅读:206      评论:0      收藏:0      [点我收藏+]

要求用C语言,不过我对C不是很熟,只在内存分配的时候使用了C,但并没有释放内存算是失误吧。

技术分享

int *arrayPrint(int**arr,int n)
{
	int*result=(int*)malloc(sizeof(int)*n*n);
	int i,j,count=0;;
	for(int m=n;m>0;m--)//右上到对角线
	{
		j=m-1;
		for(i=0;i<=n-m;i++)
		{		
			result[count]=arr[i][j];
			count++;	

			j++;

		}
	}
	for(int m=n-1;m>0;m--)//打印左下的三角
	{
		j=0;
		for(i=n-m;i<n;i++)
		{
			result[count]=arr[i][j];
			count++;	
			j++;
		}
	}
	std::cout<<std::endl;
	return result;
}

  

沿对角线打印矩形

原文:http://www.cnblogs.com/fastcam/p/4824138.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!