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:
parent
febf51beea
commit
448707b424
19
【实践课内】7.数组1/7-1 fibonacci数列.c
Normal file
19
【实践课内】7.数组1/7-1 fibonacci数列.c
Normal 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;
|
||||
}
|
BIN
【实践课内】7.数组1/7-1 fibonacci数列.jpg
Normal file
BIN
【实践课内】7.数组1/7-1 fibonacci数列.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 262 KiB |
31
【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.c
Normal file
31
【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.c
Normal 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;
|
||||
}
|
BIN
【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.jpg
Normal file
BIN
【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 299 KiB |
31
【实践课内】7.数组1/7-3 选择法排序.c
Normal file
31
【实践课内】7.数组1/7-3 选择法排序.c
Normal 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;
|
||||
}
|
BIN
【实践课内】7.数组1/7-3 选择法排序.jpg
Normal file
BIN
【实践课内】7.数组1/7-3 选择法排序.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 280 KiB |
31
【实践课内】7.数组1/7-4 冒泡法排序.c
Normal file
31
【实践课内】7.数组1/7-4 冒泡法排序.c
Normal 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;
|
||||
}
|
BIN
【实践课内】7.数组1/7-4 冒泡法排序.jpg
Normal file
BIN
【实践课内】7.数组1/7-4 冒泡法排序.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 369 KiB |
Loading…
Reference in New Issue
Block a user