1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 21:58:41 +00:00
202401-programming-assignments/【实践课外】2.选择结构1/7-3 计算天数.c

28 lines
463 B
C
Raw Normal View History

2024-10-18 10:46:44 +00:00
#include <stdio.h>
const int DAYS[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
int main() {
int y, m, d;
scanf("%4d/%2d/%2d", &y, &m, &d);
int days = 0;
for (int i = 1; i < m; i++) {
days += DAYS[i];
if (i == 2) { // 2 月涉及到闰年
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) {
days++;
}
}
}
days += d;
printf("%d\n", days);
return 0;
}