diff --git a/【额外练习】循环结构/7-1 循环-Fibonacci数列的运算.c b/【额外练习】循环结构/7-1 循环-Fibonacci数列的运算.c new file mode 100644 index 0000000..fcabf88 --- /dev/null +++ b/【额外练习】循环结构/7-1 循环-Fibonacci数列的运算.c @@ -0,0 +1,20 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + double a = 2, b = 1, sum = 0; + + for (int i = 1; i <= n; i++) { + sum += a / b; + double temp = a; + a = a + b; + b = temp; + } + + printf("%.6lf\n", sum); + + return 0; +} diff --git a/【额外练习】循环结构/7-2 循环-找数字.c b/【额外练习】循环结构/7-2 循环-找数字.c new file mode 100644 index 0000000..2ef6ef1 --- /dev/null +++ b/【额外练习】循环结构/7-2 循环-找数字.c @@ -0,0 +1,21 @@ +#include +#include + +int main() { + char str[100]; + int count = 0; + + gets(str); + + int len = strlen(str); + + for (int i = 0; i < len; i++) { + if (str[i] >= '0' && str[i] <= '9') { + count++; + } + } + + printf("%d\n", count); + + return 0; +} diff --git a/【额外练习】循环结构/7-3 循环-小智的捕食计划.c b/【额外练习】循环结构/7-3 循环-小智的捕食计划.c new file mode 100644 index 0000000..68ae3fe --- /dev/null +++ b/【额外练习】循环结构/7-3 循环-小智的捕食计划.c @@ -0,0 +1,17 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + int a = 1; + + for (int i = n; i > 2; i--) { + a = (a + 1) * 2; + } + + printf("%d\n", a); + + return 0; +} diff --git a/【额外练习】循环结构/7-5 循环-跳!.c b/【额外练习】循环结构/7-5 循环-跳!.c new file mode 100644 index 0000000..e3912dd --- /dev/null +++ b/【额外练习】循环结构/7-5 循环-跳!.c @@ -0,0 +1,20 @@ +#include + +int main() { + double a, x; + + scanf("%lf %lf", &a, &x); + + int count = 1; + double sum = a; + + while (sum < x) { + a *= 0.98; + sum += a; + count++; + } + + printf("%d\n", count); + + return 0; +} diff --git a/【额外练习】循环结构/7-6 循环-生气的峰峰.c b/【额外练习】循环结构/7-6 循环-生气的峰峰.c new file mode 100644 index 0000000..b6fac9b --- /dev/null +++ b/【额外练习】循环结构/7-6 循环-生气的峰峰.c @@ -0,0 +1,19 @@ +#include + +int a[7][2]; +int max = 0, day = 0; + +int main() { + for (int i = 0; i < 7; i++) { + scanf("%d %d", &a[i][0], &a[i][1]); + + if (a[i][0] + a[i][1] > 8 && a[i][0] + a[i][1] > max) { + max = a[i][0] + a[i][1]; + day = i + 1; + } + } + + printf("%d\n", day); + + return 0; +} diff --git a/【额外练习】循环结构/7-7 循环-平方根.c b/【额外练习】循环结构/7-7 循环-平方根.c new file mode 100644 index 0000000..8668368 --- /dev/null +++ b/【额外练习】循环结构/7-7 循环-平方根.c @@ -0,0 +1,22 @@ +#include + +int main() { + int n; + + while (1) { + scanf("%d", &n); + + if (n >= 1000) { + break; + } + } + + int i = 0; + while (i * i <= n) { + i++; + } + + printf("%d\n", i - 1); + + return 0; +}