计算天数
1 /* 2 xuejineng2016@163.com 3 2020年5月6日 4 */ 5 #include<stdio.h> 6 int main(void) 7 { 8 int year, month, day; 9 int isleap; 10 int i; 11 //用数组定义每个月的天数 12 int tab[2][13] = { {0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31} }; 13 14 scanf_s("%d/%d/%d", &year, &month, &day); 15 //闰年问题 16 isleap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); 17 for (i = 1; i < month; i++) 18 { 19 //计算从1月开始,月份的总天数 20 day = day + tab[isleap][i]; 21 } 22 printf("%d\n", day); 23 24 return 0; 25 }