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

【实践课内】4.循环结构1

This commit is contained in:
Baoshuo Ren 2024-10-25 16:00:36 +08:00
parent 52dcc31283
commit f8068129fe
Failed to extract signature
8 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int x, ans = 0;
while (scanf("%d", &x), x > 0) {
if (x % 2 == 1) {
ans += x;
}
}
printf("%d\n", ans);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int m, n, ans = 0;
scanf("%d%d", &m, &n);
for (int i = m; i <= n; i++) {
ans += i;
}
printf("%d\n", ans);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

View File

@ -0,0 +1,27 @@
#include <stdio.h>
int main() {
int n, count = 0, sum_score = 0;
scanf("%d", &n);
if (n == 0) {
printf("average = 0.0\ncount = 0\n");
} else {
for (int i = 1; i <= n; i++) {
int score;
scanf("%d", &score);
sum_score += score;
if (score >= 60) {
count++;
}
}
printf("average = %.1lf\ncount = %d\n", (double)sum_score / n, count);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 KiB

View File

@ -0,0 +1,19 @@
#include <stdio.h>
int main() {
int n, count = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (x % 4 == 0) count++;
}
printf("%d\n", count);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 KiB