1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 09:38:42 +00:00

【实践课外】8.数组2

This commit is contained in:
Baoshuo Ren 2024-11-13 11:09:36 +08:00
parent a32c304631
commit 1d65b207f1
Failed to extract signature
12 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#include <stdio.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 KiB

View File

@ -0,0 +1,29 @@
#include <stdio.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

View File

@ -0,0 +1,31 @@
#include <stdio.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 KiB

View File

@ -0,0 +1,25 @@
#include <stdio.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

View File

@ -0,0 +1,29 @@
#include <stdio.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 KiB

View File

@ -0,0 +1,32 @@
#include <stdio.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB