逆時針列印矩陣

2022-06-23 16:03:13 字數 1223 閱讀 1849

逆時針列印矩陣,輸出結果如下圖:

源**如下:

#includeusing

namespace

std;

void printmatrixincircle(int** matrix, int m, int n, int

start);

void printnumber(int

number);

//逆時針列印矩陣

void printmatrix(int m, int n, int**matrix)

int start = 0

;

while (m>start*2&&n>start*2

)

}

//在圓圈中列印矩陣,列印一圈分4種情況:一步,二步,三步,四步

void printmatrixincircle(int** matrix, int m, int n, int

start)

//從左到右列印一行

if (start

}

//從下到上列印一行

if (start < endx&&start

} //從右到左列印一行

if (start < endx-1 && start

} }

//列印數字

void printnumber(int

number)

//********************測試**********************

void test(int m, int

n)

int** matrix = new

int*[n];

for ( i = 0; i < n; i++)

} printmatrix( m, n, matrix);

cout

<

for ( i = 0; i < n; ++i)

delete(int*)matrix[i];

delete

matrix;

}

intmain()