题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main() { int a, b; int year, month, day; int sum = 0; scanf("%d %d %d", &year, &month, &day); int days[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };//平年 int days2[] = { 31,29,31,30,31,30,31,31,30,31,30,31 };//闰年 for (int i = 1; i < month; i++) { if ((year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0))) { sum += days2[i - 1]; } else sum += days[i - 1]; } printf("%d", sum + day); return 0; }