计算天数
1 #include<stdio.h> 2 3 int main(void) 4 { 5 int year; 6 int month; 7 int day; 8 int a[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 9 int days = 0; 10 11 scanf_s("%d/%2d/%2d", &year, &month, &day); 12 13 if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) 14 { 15 a[1] = 29; 16 } 17 18 for (int i = 1; i < month; i++) 19 { 20 days = days + a[i]; 21 } 22 23 days = days + day; 24 25 printf("%d\n", days); 26 27 return 0; 28 }
计算天数,用了数组。