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:
parent
52dcc31283
commit
f8068129fe
15
【实践课内】4.循环结构1/7-1 求奇数和.c
Normal file
15
【实践课内】4.循环结构1/7-1 求奇数和.c
Normal 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;
|
||||
}
|
BIN
【实践课内】4.循环结构1/7-1 求奇数和.jpg
Normal file
BIN
【实践课内】4.循环结构1/7-1 求奇数和.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 275 KiB |
15
【实践课内】4.循环结构1/7-2 100以内的加法.c
Normal file
15
【实践课内】4.循环结构1/7-2 100以内的加法.c
Normal 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;
|
||||
}
|
BIN
【实践课内】4.循环结构1/7-2 100以内的加法.jpg
Normal file
BIN
【实践课内】4.循环结构1/7-2 100以内的加法.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 304 KiB |
27
【实践课内】4.循环结构1/7-3 统计学生平均成绩与及格人数.c
Normal file
27
【实践课内】4.循环结构1/7-3 统计学生平均成绩与及格人数.c
Normal 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;
|
||||
}
|
BIN
【实践课内】4.循环结构1/7-3 统计学生平均成绩与及格人数.jpg
Normal file
BIN
【实践课内】4.循环结构1/7-3 统计学生平均成绩与及格人数.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 321 KiB |
19
【实践课内】4.循环结构1/7-4 循环-4 的倍数.c
Normal file
19
【实践课内】4.循环结构1/7-4 循环-4 的倍数.c
Normal 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;
|
||||
}
|
BIN
【实践课内】4.循环结构1/7-4 循环-4 的倍数.jpg
Normal file
BIN
【实践课内】4.循环结构1/7-4 循环-4 的倍数.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 294 KiB |
Loading…
Reference in New Issue
Block a user