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

【额外练习】循环结构

This commit is contained in:
Baoshuo Ren 2024-11-18 23:10:07 +08:00
parent 8ddf41bf24
commit 1fbe983580
Failed to extract signature
6 changed files with 119 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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