日期运算
程序员文章站
2022-04-09 18:18:04
日期运算代码如下: ......
日期运算代码如下:
1 #include <cstdio> 2 #include <cstdlib> 3 4 #define n 12 5 6 int main() 7 { 8 int a[n] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 9 int b[n] = { 0 }; 10 int year, mon, day, i, j, total; 11 for (i = 0; i < n; i++) 12 for (j = 0; j <= i; j++) 13 b[i] += a[j]; 14 15 while (scanf_s("%d%d%d", &year, &mon, &day) != eof) 16 { 17 total = 0; 18 //for (i = 0; i < mon - 1; i++) 19 // total += a[i]; 20 total += b[mon - 2]; 21 if (mon > 2) 22 total += year % 4 == 0 && year % 100 != 0 || year % 400 == 0; //判断闰年 23 total += day; 24 printf("%d-%02d-%02d is %dth\n", year, mon, day, total); 25 } 26 system("pause"); 27 return 0; 28 }