C++输出数字回形矩阵
发布网友
发布时间:2023-12-23 00:26
我来回答
共1个回答
热心网友
时间:2024-08-02 01:17
void matrix(int n) {
char d[2*9][2*9];
if (n > 0 && n <= 9) {
int t = 2*n - 1;
int i, j;
int s = 0, e = t-1;
for (i = 0; i < n; i++) {
for (j = s; j <= e; j++){
d[i][j] = d[j][i] =
d[j][e] = d[e][j]
= n - i + '0';
}
s++;
e--;
}
for (i = 0; i < t; i++) {
d[i][t] = 0;
printf("%s\n", d[i]);
}
}
}
int main()
{
int n;
scanf("%d", &n);
matrix(n);
return 0;
}