C语言万年历(代码说明)

上传人:汽*** 文档编号:490348313 上传时间:2022-12-23 格式:DOC 页数:5 大小:18.01KB
返回 下载 相关 举报
C语言万年历(代码说明)_第1页
第1页 / 共5页
C语言万年历(代码说明)_第2页
第2页 / 共5页
C语言万年历(代码说明)_第3页
第3页 / 共5页
C语言万年历(代码说明)_第4页
第4页 / 共5页
C语言万年历(代码说明)_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《C语言万年历(代码说明)》由会员分享,可在线阅读,更多相关《C语言万年历(代码说明)(5页珍藏版)》请在金锄头文库上搜索。

1、/*本程序在 Microsoft Visual Studio 2010 旗舰版中测试通过*/#include stdio.h#include stdlib.h#include time.h#include conio.h#define KEYUP 72/宏定义键盘的键值()#define KEYDOWN 80/宏定义键盘的键值()#define KEYLEFT 75/宏定义键盘的键值()#define KEYRIGHT 77/宏定义键盘的键值()/函数声明部分const int isLeap(int year);const int getMonthDays(int year,int month

2、);const int yearDays(int year);void printCalendar(int year,int month);void main()int year,month;int action = 0;/获取本地当前的年份和月份time_t timep;struct tm *p;time(&timep);p = localtime(&timep);year = p-tm_year+1900;/获取本地当前的年份month = p-tm_mon + 1;/获取本地当前的月份while(1)printf(tt %d 年%d 月n,year,month);printCalenda

3、r(year,month);action = getch();system(cls);switch(action)case KEYUP:year+;break;case KEYDOWN:year-;break;case KEYLEFT:month-;if(month 12)month = 1; break;/判断 year 是否是润年 返回 1 为闰年const int isLeap(int year)if(year%4=0&year%100!=0|year%400=0)return 1;elsereturn 0;/*计算 year 年的 month 月是多少天*返回值:整型,天数*/cons

4、t int getMonthDays(int year,int month)switch(month)case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;break;case 4:case 6:case 9:case 11:return 30;break;case 2:if(isLeap(year)return 29;elsereturn 28;break;default:return 0;break;/计算 year 年的天数const int yearDays(int year) if(isLeap(year)retur

5、n 366;elsereturn 365;/*判断 year 年 month 月 day 天时星期几*返回值:0,1,2,3,4,5,6*/const int isWeek(int year,int month,int day)int days = 0;int i;/计算前 year 年有多少天for(i=1;iyear;i+)days = days + yearDays(i);/计算 year 年的前 month 个月有多少天for(i=1;imonth;i+)days = days + getMonthDays(year,i);/从公元 1 年days = days + day;retur

6、n days%7;/按日历的格式打印 year 年 month 月的日历void printCalendar(int year,int month)const char *week= 日,一,二,三,四,五,六;int i;int row = 0;for(i=0;i7;i+)printf(%st,weeki);printf(n);/判断 year 年 month 月 1 日时星期几for(i=0;iisWeek(year,month,1);i+)printf(t);for(i=0;igetMonthDays(year,month);i+)printf(%dt,i+1);/如果是星期六就换行打印日期if(isWeek(year,month,i+1) = 6)row +;if(row = 2)printf( );if(row = 3)printf( );if(row = 4) printf( );printf(nn);printf(n);CreateDBW制作2012年12月7日

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 文学/艺术/历史 > 人文/社科

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号