成都创新互联网站制作重庆分公司

C语言怎么实现万年历

本篇内容介绍了“C语言怎么实现万年历”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

创新互联主营乾安网站建设的网络公司,主营网站建设方案,APP应用开发,乾安h5微信小程序定制开发搭建,乾安网站营销推广欢迎乾安等地区企业咨询

主函数所在源码

#include #include #include int GetWeek(int year,int month,int day);//求今天是周几。周四就返回 4 。周日 返回 0;非法返回 -1; int GetDaysInMonth(int year,int month);/*求指定月总共多少天*/int CreateMonthData(int MonthDay[6][7],int year,int month);void PrintMonth(int MonthDay[6][7]);int main(){ int MDate[6][7] = {{0}};  int y = 0; int m = 0; int ret = 0;  printf("Plear input year month:\n"); scanf("%d%d",&y,&m); if(m <= 0 || m > 12) { printf("Your month is invalid\n"); return 1; }  ret = CreateMonthData(MDate,y,m); if(ret == 0) { PrintMonth(MDate); } return 0;} int CreateMonthData(int MonthDay[6][7],int year,int month){ int week = GetWeek(year,month,1);//返回第几周。  int day = 1; int i = 0; int j = 0; int daysInMonth = GetDaysInMonth(year,month);//当月天数。  if(week < 0) { printf("GetWeek Failed\n"); return -1; }  /*给第0行赋值*/  for(j = 0;j < 7;j++) { if(j < week) { MonthDay[0][j] = 0; } else { MonthDay[0][j] = day; day++; } } /*给第1~5赋值*/ for(i = 1;i < 6;i++) { for(j = 0;j < 7;j++) { if(day > daysInMonth) { MonthDay[i][j] = 0; } else { MonthDay[i][j] = day; day++; } } } return 0;} /*将二维数组中本月日期按如下形式显示:以2017年1月为例*//* 日 一 二 三 四 五 六 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 0 0 0 0 0 0 0 0 0 0 0*/void PrintMonth(int MonthDay[6][7]){ int i=0; int j=0; printf(" 日 一 二 三 四 五 六\n"); for(i=0;i<6;i++) { for(j=0;j<7;j++) { printf("%2d ",MonthDay[i][j]); } printf("\n"); } }

第二个文件源码

#include #include #include //润年 int LeapDays[12] = {31,29,31,30,31,30,31,31,30,31,30,31};//非闰年 int CommonDays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};//闰年返回 1 ,否则返回 0; int IsLeapYear(int year){ if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return 1; } else { return 0; }}// 输入非法 返回 0;否则返回 1; int IsValidDate(int year,int month,int day){ int ret = 1; if(month < 1 || month > 12 || day < 1 || year <= 0) {  return 0; } if(IsLeapYear(year)) {  if(day > LeapDays[month - 1])  {   ret = 0;  } } else {  if(day > CommonDays[month - 1])  {   ret = 0;  } } return ret;}/*求这一天是当年的第多少天*/int GetDaysInYear(int year,int month,int day){ int sum=0;//总天数  int isrun=IsLeapYear(year);//闰年返回 1 ;否则返回 0; int i=0; int j=0; if(isrun) { for(i=0;i

“C语言怎么实现万年历”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


当前标题:C语言怎么实现万年历
分享地址:http://cxhlcq.com/article/gjhsdo.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部