1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00
202401-programming-assignments/【实践课外】4.循环结构1/7-5 循环-求和.c

20 lines
304 B
C
Raw Normal View History

2024-10-25 08:43:54 +00:00
#include <stdio.h>
int main() {
int m, n, s1 = 0, s2 = 0;
scanf("%d%d", &m, &n);
for (int i = m; i <= n; i++) {
if (i % 2 == 1) {
s1 += i * i;
} else { // i % 2 == 0
s2 += i * i * i;
}
}
printf("%d %d\n", s1, s2);
return 0;
}