一个下午加一个晚上完成这个万年历程序,这是我目前为止写的最长的程序了,完成后运行成功的那一瞬间还是有一些小成就感的。

这个程序目前有五个功能:

1.查看当前年历或月历;

2.搜索某年年历或某月月历;

3.查询某天是星期几;

4.判断某年是否为闰年

5.查询历史上某年是该年的第几天

代码如下:

-----------------------------------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>
#include<math.h>
#include "time.h" int head()          //显示欢迎界面,返回功能值
{int select;printf("\n\n");printf("\t\t\t<--欢迎使用万年历-->\n\n");printf("\t\t****************************************\n");printf("\t\t请选择要使用的功能:\n\n");printf("\t\t\t1.查看当年年历或当月月历\n");printf("\t\t\t2.搜素某年的年历或某月的日历\n");printf("\t\t\t3.查询历史上某日为星期几\n");printf("\t\t\t4.判断历史上某年是否为闰年\n");printf("\t\t\t5.查询历史上某天是该年的第几天\n");printf("\t\t\t6.退出\n");printf("\t\t****************************************\n");printf("\t\t\t请选择<1,2,3,4,5,6>:"); scanf("%d",&select) ;printf("\n");return(select);
}void searchhead(int year,int month)            //月历的表头 {printf("\t%d年%d月\n",year,month);printf("\t***************************************************\n")  ;printf("\t日\t一\t二\t三\t四\t五\t六\n"); }int monthnum(int year,int month)         //返回月份多少天
{int a1[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int a2[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};if(leapyear(year)==1){return(a2[month]);}else{return(a1[month]);}
}int leapyear(int year)         //判断是否为闰年
{if(year%4==0&&year%100!=0||year%4==0&&year%400==0) {return(1);}         else{return(0);}
}  int  week(int year,int month,int day)            //根据蔡勒公式计算星期几
{int w ,c,y;if(month==1) {month=13;year=year-1;}if(month==2) {month=14;year=year-1;}y=year%100;c=(year/1000)*10+(year/100%10);if(y==0){c=c-1;}w=y+floor(y/4)+floor(c/4)-2*c+floor(26*(month+1)/10.0)+day-1;
while(w<0){w=w+7;}if(w%7==0){return(7);}
return(w%7);
}int function3()            //第三个功能查询历史上某日为星期几的模块
{int year=0,month=1,day=1;printf("-----查询历史上某日为星期几-----\n");printf("\n");do{if(year<0){printf("\t系统提示:您输入了错误的年份请从新输入...\n");}printf("\t请输入要查询的年份:");scanf("%d",&year);printf("\n");} while(year<0);do{if(month<1||month>12){printf("\t系统提示:您输入了错误的月份请从新输入...\n");}
printf("\t请输入%d年的第几月:",year);scanf("%d",&month);printf("\n");} while(month<1||month>12);do{if(day<1||day>31){printf("\t系统提示:您输入了错误的日期请从新输入...\n");}printf("\t请输入%d年%d月的第几天:",year,month);scanf("%d",&day);printf("\n");} while(day<1||day>31);printf("\t您查询的%d年%d月%d号是星期%d\n\n",year,month,day,week(year,month,day));
}void function4()           //功能四判断历史上某年是否为闰年模块
{int year=0;printf("-----判断历史上某年是否为闰年-----\n");do
{if(year<0){printf("\t系统提示:您输入了错误的年份请从新输入...\n");}printf("\t请输入要查询的年份:");scanf("%d",&year);printf("\n");} while(year<0);if(leapyear(year)==1){printf("\t您查询的%d年是闰年\n\n",year);  }else{printf("\t您查询的%d年不是闰年\n\n",year);   }}int function2()           //模块二:搜素某年的年历或某月的日历模块
{int year=0,month=1,i,j,spacenum,count;printf("-----搜素某年的年历或某月的日历-----\n\n");do{if(year<0){printf("\t系统提示:您输入了错误的年份请从新输入...\n");}printf("\t请输入要查看的年份:");scanf("%d",&year);printf("\n");} while(year<0);do{if(month<0||month>12){printf("\t系统提示:您输入了错误的月份请从新输入...\n");}printf("\t请输入查看%d年的第几月,若想查看%d年年历请输入零:",year,year);scanf("%d",&month);printf("\n");} while(month<0||month>12);if(month!=0){searchhead(year,month)   ;spacenum=week(year,month,1);if(spacenum!=7)          //输出空格 {for(i=1;i<=spacenum;i++){printf("\t ");}   }count=spacenum;for(i=1;i<=monthnum(year,month);i++)    {printf("\t%d ",i);count++;if(count%7==0){printf("\n");}    }}if(month==0){for(j=1;j<=12;j++){searchhead(year,j)   ;spacenum=week(year,j,1);if(spacenum!=7)          //输出空格 {for(i=1;i<=spacenum;i++){printf("\t ");}   }count=spacenum;for(i=1;i<=monthnum(year,j);i++)    {printf("\t%d ",i);count++;if(count%7==0){printf("\n");}    }printf("\n\n");  }}}int nowyear()    //获取系统的年份     { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime );return( timeinfo->tm_year+1900) ;  }    int nowmonth()    //获取系统的月份{time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime );return(timeinfo->tm_mon+1  ) ;  }int function1()            //模块一:查看当年年历或当月月历
{int k,i,j,spacenum,count;printf("-----查看当年年历或当月月历-----\n\n");printf("\t您想查看今年的年历还是当月的月历,请输入1【年历】或0【月历】:");scanf("%d",&k);printf("\n");if(k==0){searchhead(nowyear(),nowmonth())  ;spacenum=week(nowyear(),nowmonth(),1);if(spacenum!=7)            //输出空格 {for(i=1;i<=spacenum;i++){printf("\t ");}   }count=spacenum;for(i=1;i<=monthnum(nowyear(),nowmonth());i++)  {printf("\t%d ",i);count++;if(count%7==0){printf("\n");}    }}if(k==1){for(j=1;j<=12;j++){searchhead(nowyear(),j)  ;spacenum=week(nowyear(),j,1);if(spacenum!=7)         //输出空格 {for(i=1;i<=spacenum;i++){printf("\t ");}   }count=spacenum;for(i=1;i<=monthnum(nowyear(),j);i++)   {printf("\t%d ",i);count++;if(count%7==0){printf("\n");}    }printf("\n\n");  }}}void function5()         //功能五:查询历史上某天是该年的第几天
{int year=0,month=1,day=1,i,s=0;int a[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};int b[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf("-----查询历史上某天是该年的第几天-----\n");printf("\n");do{if(year<0){printf("\t系统提示:您输入了错误的年份请从新输入...\n");}printf("\t请输入要查询的年份:");scanf("%d",&year);printf("\n");} while(year<0);do{if(month<1||month>12){printf("\t系统提示:您输入了错误的月份请从新输入...\n");}
printf("\t请输入%d年的第几月:",year);scanf("%d",&month);printf("\n");} while(month<1||month>12);do{if(day<1||day>31){printf("\t系统提示:您输入了错误的日期请从新输入...\n");}printf("\t请输入%d年%d月的第几天:",year,month);scanf("%d",&day);printf("\n");} while(day<1||day>31);s=s+day;if(leapyear(year)==1){for(i=1;i<month;i++){s=s+a[i];}}else{for(i=1;i<month;i++){s=s+b[i];}}printf("\t您查询的%d年%d月%d号是该年的第%d天\n",year,month,day,s);
}main()
{int select;char ch;while(1){ select=head();if(select==1){function1();} if(select==2){function2();} if(select==3){function3();} if(select==4) {function4();    }if(select==5){function5();}  if(select==6){break;} }
}

c语言实现万年历程序相关推荐

  1. c语言万年历程序原理,C语言实现万年历程序

    C语言实现万年历程序 #include int year(int y) { if ((y%4==0) && (y%100!=0) || y%400==0) return 366; el ...

  2. c语言万年历代码作业,用c语言编写万年历程序

    用c语言编写万年历程序 <C 程序设计>课程设计报告 2011-2012学年第二学期 设计题目:万年历的设计 指导教师: 李素若 完成时间:2012 年 6月 1日至 2011年 6月 2 ...

  3. 原 C语言实现万年历程序,C语言实现万年历源码

    本文实例为大家分享了C语言实现万年历的具体代码,供大家参考,具体内容如下 主函数所在源码 #include #include #include int GetWeek(int year,int mon ...

  4. c语言编写万年历程序显示时间,C语言格式化输出日历(万年历)

    C语言控制台输出日历.先输入年份,然后输入每行显示的月份个数. 如图: 代码如下: #include int main(void) { int a, i, j, n, k, t, w, x, y, z ...

  5. c语言万年历查询程序代码,C语言 万年历程序(示例代码)

    C语言 万年历程序 原代码:[email protected]:~/c++$ cat 123.c #include #define Mon   1 #define Tues  2 #define We ...

  6. C语言实现万年历(附代码) 小白完成的第一个C语言程序,希望大家多多关注,点赞

    C语言实现万年历 前言:本文章向大家介绍如何使用C语言代码实现万年历使用实例,讲解编写万年历的方法,教你轻松学会写出万年历.这个小程序算是我自己写的第一个比较完整的小程序,算是对大一上学期学习的C语言 ...

  7. 教你用C语言编写万年历,程序员超乎你的想象!

    学了C语言的小编闲来无事就想搞点事情做,发现可以用C语言做万年历,计算器,俄罗斯方块儿游戏之类的,就从万年历开始玩耍啦. Step 1. 新建一个程序 制作一个应用当然必不可少的就是新建程序啦,小编这 ...

  8. c语言万年历流程图加程序,基于C语言的万年历(内附程序).pdf

    基于C语言的万年历(内附程序) 课程设计 课程名称 C语言程序课程设计 题目名称 编写万年历系统 学生学院 专业班级 学 号 学生姓名 指导教师 2009 年 06 月 04 日 广东工业大学课程设计 ...

  9. c语言小程序 万年历,C语言实现万年历小程序

    这篇文章主要为大家详细介绍了C语言实现万年历小程序,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 一.杂谈 大一学了C之后一直困惑,C到底怎么用?它不像HTML那么直观 ...

  10. 用linux下的C语言编程万年历,C语言 万年历程序

    C语言 万年历程序 原代码:chunli@Linux:~/c++$ cat 123.c #include #define Mon   1 #define Tues  2 #define Wed   3 ...

最新文章

  1. 2022-2028年中国煤及褐煤行业发展现状及未来前景分析报告
  2. 云炬创业政策学习笔记20210115
  3. Solaris 10主动安顿DVD运用步骤
  4. Win10系统浏览器字体乱码如何解决
  5. Java中的标识符及其命名规则
  6. 公司冷备服务器1.100切换到1.99
  7. [BZOJ2282]消防
  8. Ubuntu编译:error: ‘usleep’ was not declared in this scope
  9. 僵化封闭果然是主流——评华为会员资格被暂停
  10. Mac 修改VIM中C语言函数高亮显示
  11. 北斗卫星广播星历计算卫星位置
  12. 基于SNN脉冲神经网络的Hebbian学习训练过程matlab仿真
  13. html中url英文全称,URL的英文全称
  14. Spring Boot 学习[四] web项目实战训练(增删改查,分页,排序)
  15. 《Dreamweaver CS6 完全自学教程》笔记 第十七章:Spry 框架技术
  16. 7-28 实验3_11_鸡兔同笼吗? (100 分)
  17. [渝粤教育] 南京邮电大学 有机电子学(双语) 参考 资料
  18. PVP:手游进程的终点
  19. 唐伯猫:论强势文化与弱势文化
  20. 正阳-本站汇总(长期更新)

热门文章

  1. 《网络运维 - 基础知识》
  2. 软件学院本科毕业设计论文格式详解
  3. 百度网盘正版免费扩容教程
  4. alpha-beta剪枝算法原理(附代码)
  5. PDF破解FileOpenPlugin加密的方法
  6. AD(Altium Designer)软件中原理图自制模板(图框)的妙用
  7. Android 获取文件后缀名
  8. tf data 常用操作
  9. umijs 隐藏开发工具_Umi UI 插件开发 - UmiJS 中文文档
  10. Numpy:numpy包下载并导入Pycharm的方法