沿对角线打印二维数组

要求用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;
}

  

原文地址:https://www.cnblogs.com/fastcam/p/4824138.html