首页 > 代码库 > 顺时针打印旋转打印矩阵

顺时针打印旋转打印矩阵

#include "stdafx.h"
#include <iostream>
using namespace std;


void loopShow(int s[][6],int m,int n)
{
	int min_i=0,max_i=m-1;
	int min_j=0,max_j=n-1;

	while(min_i<=max_i && min_j<=max_j)
	{
		for(int k=min_j;k<max_j;k++)
		{
			cout<<s[min_i][k]<<" ";
		}
		
		for(int k=min_i;k<max_i;k++)
		{
			cout<<s[k][max_j]<<" ";
		}

		for(int k=max_j;k>min_j;k--)
		{
			cout<<s[max_i][k]<<" ";
		}
		for(int k=max_i;k>min_i;k--)
		{
			cout<<s[k][min_j]<<" ";
		}

		min_i++;
		min_j++;
		max_i--;
		max_j--;
	}
	cout<<endl;

	return;
}

int s[][6]=
{
	{1,2,3,4,5,1},
	{6,7,8,9,10,1},
	{11,12,13,14,15,1},
	{16,17,18,19,20,1}
};

int main(void)
{
	loopShow(s,4,6);

	system("pause");
	return 0;
}


顺时针打印旋转打印矩阵