题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
#include <stdio.h> int main() { int year = 0; int month = 0; int day = 0; scanf("%d %d %d", &year, &month, &day); if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) { int arr1[12] = { 31,29,31,30, 31, 30, 31, 31, 30, 31,30, 31 }; int k = 0; int* p = arr1; int sum = day; for (int i = 0; i < month-1; i++) { sum =sum+ *(p+i ); } printf("%d\n",sum); } else { int arr2[12] = { 31,28,31,30, 31, 30, 31, 31, 30, 31,30, 31 }; int k = 0; int* p = arr2; int sum = day; for (int i = 0; i < month - 1; i++) { sum = sum + *(p + i); } printf("%d\n", sum); } return 0; }