diff --git a/【实践课内】7.数组1/7-1 fibonacci数列.c b/【实践课内】7.数组1/7-1 fibonacci数列.c new file mode 100644 index 0000000..27e93e2 --- /dev/null +++ b/【实践课内】7.数组1/7-1 fibonacci数列.c @@ -0,0 +1,19 @@ +#include + +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; +} diff --git a/【实践课内】7.数组1/7-1 fibonacci数列.jpg b/【实践课内】7.数组1/7-1 fibonacci数列.jpg new file mode 100644 index 0000000..e22f2f8 Binary files /dev/null and b/【实践课内】7.数组1/7-1 fibonacci数列.jpg differ diff --git a/【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.c b/【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.c new file mode 100644 index 0000000..dc7cfb5 --- /dev/null +++ b/【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.c @@ -0,0 +1,31 @@ +#include + +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; +} diff --git a/【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.jpg b/【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.jpg new file mode 100644 index 0000000..ee96787 Binary files /dev/null and b/【实践课内】7.数组1/7-2 输出去掉最大值和最小值后剩下数据的和.jpg differ diff --git a/【实践课内】7.数组1/7-3 选择法排序.c b/【实践课内】7.数组1/7-3 选择法排序.c new file mode 100644 index 0000000..ec4faeb --- /dev/null +++ b/【实践课内】7.数组1/7-3 选择法排序.c @@ -0,0 +1,31 @@ +#include + +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; +} diff --git a/【实践课内】7.数组1/7-3 选择法排序.jpg b/【实践课内】7.数组1/7-3 选择法排序.jpg new file mode 100644 index 0000000..fe3424a Binary files /dev/null and b/【实践课内】7.数组1/7-3 选择法排序.jpg differ diff --git a/【实践课内】7.数组1/7-4 冒泡法排序.c b/【实践课内】7.数组1/7-4 冒泡法排序.c new file mode 100644 index 0000000..eb2fcc7 --- /dev/null +++ b/【实践课内】7.数组1/7-4 冒泡法排序.c @@ -0,0 +1,31 @@ +#include + +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; +} diff --git a/【实践课内】7.数组1/7-4 冒泡法排序.jpg b/【实践课内】7.数组1/7-4 冒泡法排序.jpg new file mode 100644 index 0000000..4c1e355 Binary files /dev/null and b/【实践课内】7.数组1/7-4 冒泡法排序.jpg differ