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

26 lines
358 B
C
Raw Normal View History

2024-10-30 03:44:18 +00:00
#include <stdio.h>
int main() {
int a, b, sum = 0;
scanf("%d %d", &a, &b);
for (int i = 0; i < (b - a + 1); i++) {
printf("%5d", a + i);
sum += a + i;
if (i % 5 == 4) {
printf("\n");
}
}
if ((b - a) % 5 != 4) {
printf("\n");
}
printf("Sum = %d\n", sum);
return 0;
}