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

【实践课内】7.数组1

This commit is contained in:
Baoshuo Ren 2024-11-06 10:32:30 +08:00
parent febf51beea
commit 448707b424
Failed to extract signature
8 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#include <stdio.h>
int f[20] = {0, 1};
int main() {
for (int i = 2; i < 20; i++) {
f[i] = f[i - 1] + f[i - 2];
}
for (int i = 1; i <= 12; i++) {
printf("%6d", f[i]);
if (i % 3 == 0) {
printf("\n");
}
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

View File

@ -0,0 +1,31 @@
#include <stdio.h>
int a[10], max = -1e8, min = 1e8, sum;
int main() {
for (int i = 1; i <= 6; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= 6; i++) {
if (a[i] > max) {
max = a[i];
}
if (a[i] < min) {
min = a[i];
}
}
for (int i = 1; i <= 6; i++) {
if (a[i] == max || a[i] == min) {
continue;
}
sum += a[i];
}
printf("%d\n", sum);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

View File

@ -0,0 +1,31 @@
#include <stdio.h>
int n, a[20];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i] < a[j]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
for (int i = 1; i <= n; i++) {
if (i < n) {
printf("%d ", a[i]);
} else {
printf("%d\n", a[i]);
}
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB

View File

@ -0,0 +1,31 @@
#include <stdio.h>
int n, k, a[200];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= k; i++) {
for (int j = 2; j <= n; j++) {
if (a[j] < a[j - 1]) {
int t = a[j];
a[j] = a[j - 1];
a[j - 1] = t;
}
}
}
for (int i = 1; i <= n; i++) {
if (i < n) {
printf("%d ", a[i]);
} else {
printf("%d\n", a[i]);
}
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 KiB