diff --git a/【实践课外】8.数组2/7-25 数组-杨辉三角.c b/【实践课外】8.数组2/7-25 数组-杨辉三角.c new file mode 100644 index 0000000..5b24a7f --- /dev/null +++ b/【实践课外】8.数组2/7-25 数组-杨辉三角.c @@ -0,0 +1,27 @@ +#include + +int n, f[25][25]; + +int main() { + scanf("%d", &n); + + for (int i = 1; i <= n; i++) { + f[i][1] = f[i][i] = 1; + } + + for (int i = 2; i <= n; i++) { + for (int j = 2; j < i; j++) { + f[i][j] = f[i - 1][j - 1] + f[i - 1][j]; + } + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + printf("%7d", f[i][j]); + } + + printf("\n"); + } + + return 0; +} diff --git a/【实践课外】8.数组2/7-25 数组-杨辉三角.jpg b/【实践课外】8.数组2/7-25 数组-杨辉三角.jpg new file mode 100644 index 0000000..2c1c536 Binary files /dev/null and b/【实践课外】8.数组2/7-25 数组-杨辉三角.jpg differ diff --git a/【实践课外】8.数组2/7-26 数组-对角线求和.c b/【实践课外】8.数组2/7-26 数组-对角线求和.c new file mode 100644 index 0000000..aca9519 --- /dev/null +++ b/【实践课外】8.数组2/7-26 数组-对角线求和.c @@ -0,0 +1,29 @@ +#include + +int n, mat[105][105], sum1 = 0, sum2 = 0; + +int main() { + scanf("%d", &n); + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + scanf("%d", &mat[i][j]); + } + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + if (i == j) { + sum1 += mat[i][j]; + } + + if (i + j == n + 1) { + sum2 += mat[i][j]; + } + } + } + + printf("%d %d\n", sum1, sum2); + + return 0; +} diff --git a/【实践课外】8.数组2/7-26 数组-对角线求和.jpg b/【实践课外】8.数组2/7-26 数组-对角线求和.jpg new file mode 100644 index 0000000..b32a949 Binary files /dev/null and b/【实践课外】8.数组2/7-26 数组-对角线求和.jpg differ diff --git a/【实践课外】8.数组2/7-27 数组-矩阵最小值.c b/【实践课外】8.数组2/7-27 数组-矩阵最小值.c new file mode 100644 index 0000000..05879f1 --- /dev/null +++ b/【实践课外】8.数组2/7-27 数组-矩阵最小值.c @@ -0,0 +1,31 @@ +#include + +int m, n, mat[25][25], min, min_i, min_j; + +int main() { + scanf("%d%d", &m, &n); + + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + scanf("%d", &mat[i][j]); + } + } + + min = mat[1][1]; + min_i = 1; + min_j = 1; + + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + if (mat[i][j] < min) { + min = mat[i][j]; + min_i = i; + min_j = j; + } + } + } + + printf("%d %d %d\n", min, min_i, min_j); + + return 0; +} diff --git a/【实践课外】8.数组2/7-27 数组-矩阵最小值.jpg b/【实践课外】8.数组2/7-27 数组-矩阵最小值.jpg new file mode 100644 index 0000000..6fbd3d6 Binary files /dev/null and b/【实践课外】8.数组2/7-27 数组-矩阵最小值.jpg differ diff --git a/【实践课外】8.数组2/7-4 矩阵运算.c b/【实践课外】8.数组2/7-4 矩阵运算.c new file mode 100644 index 0000000..2fa3f31 --- /dev/null +++ b/【实践课外】8.数组2/7-4 矩阵运算.c @@ -0,0 +1,25 @@ +#include + +int n, mat[15][15], sum = 0; + +int main() { + scanf("%d", &n); + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + scanf("%d", &mat[i][j]); + } + } + + for (int i = 1; i <= n - 1; i++) { + for (int j = 1; j <= n - 1; j++) { + if (i + j != n + 1) { // 剔除副对角线 + sum += mat[i][j]; + } + } + } + + printf("%d\n", sum); + + return 0; +} diff --git a/【实践课外】8.数组2/7-4 矩阵运算.jpg b/【实践课外】8.数组2/7-4 矩阵运算.jpg new file mode 100644 index 0000000..0aa9ead Binary files /dev/null and b/【实践课外】8.数组2/7-4 矩阵运算.jpg differ diff --git a/【实践课外】8.数组2/7-6 方阵循环右移.c b/【实践课外】8.数组2/7-6 方阵循环右移.c new file mode 100644 index 0000000..cabea92 --- /dev/null +++ b/【实践课外】8.数组2/7-6 方阵循环右移.c @@ -0,0 +1,29 @@ +#include + +int m, n, mat[10][10]; + +int main() { + scanf("%d%d", &m, &n); + + m %= n; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + scanf("%d", &mat[i][j]); + } + } + + for (int i = 0; i < n; i++) { + for (int j = n - m; j < n; j++) { + printf("%d ", mat[i][j]); + } + + for (int j = 0; j < n - m; j++) { + printf("%d ", mat[i][j]); + } + + printf("\n"); + } + + return 0; +} diff --git a/【实践课外】8.数组2/7-6 方阵循环右移.jpg b/【实践课外】8.数组2/7-6 方阵循环右移.jpg new file mode 100644 index 0000000..54ac191 Binary files /dev/null and b/【实践课外】8.数组2/7-6 方阵循环右移.jpg differ diff --git a/【实践课外】8.数组2/7-7 螺旋方阵.c b/【实践课外】8.数组2/7-7 螺旋方阵.c new file mode 100644 index 0000000..9072c67 --- /dev/null +++ b/【实践课外】8.数组2/7-7 螺旋方阵.c @@ -0,0 +1,32 @@ +#include + +int n, mat[15][15]; + +int main() { + scanf("%d", &n); + + int x = 1, y = 1, dx = 0, dy = 1; + + for (int i = 1; i <= n * n; i++) { + mat[x][y] = i; + + if (x + dx > n || x + dx < 1 || y + dy > n || y + dy < 1 || mat[x + dx][y + dy]) { + int tmp = dx; + dx = dy; + dy = -tmp; + } + + x += dx; + y += dy; + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + printf("%3d", mat[i][j]); + } + + printf("\n"); + } + + return 0; +} diff --git a/【实践课外】8.数组2/7-7 螺旋方阵.jpg b/【实践课外】8.数组2/7-7 螺旋方阵.jpg new file mode 100644 index 0000000..e71dccc Binary files /dev/null and b/【实践课外】8.数组2/7-7 螺旋方阵.jpg differ