设为首页 加入收藏

TOP

日期运算
2019-02-15 00:07:58 】 浏览:82
Tags:日期 运算

日期运算代码如下:

 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 }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇n进制转十进制 下一篇C语言学习记录_2019.02.12

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目