您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > c语言课程设计简易万年历
/**湖北师范学院信息工程1203班朱文峰**简易万年历*1、输入年份,判断是否为闰年*2、输入年月日,判断改日为星期几*3、输入年份,打出12个月历,输入月份,打出该月的日历*4、要求用多个函数实现*/#includestdio.h#includestdlib.h#includewindows.h//每月的天数,闰年二月要加1intdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};//判断是否位闰年intisLeapYear(intyear){if(year%4==0&&year%100!=0||year%400==0)return1;elsereturn0;}//判断某天为星期几intwhichWeekday(intyear,intmonth,intday){intweekday;//公式中要把1月和2月换成是上一年的13月和14月if(month==1||month==2){month+=12;year-=1;}//公式weekday=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;returnweekday+1;}//打印某年某月的月历voidyearMonth(intyear,intmonth){inti,j=0;intweekday;//计算这个月第一天是星期几weekday=whichWeekday(year,month,1);printf(\n%d年%d月\n,year,month);printf(------------------------------------------------\n);printf(星期一星期二星期三星期四星期五星期六星期天\n);if(isLeapYear(year)&&month==2)days[1]=days[1]+1;printf();for(i=1;iweekday;i++)printf();for(i=0;i8-weekday;i++){printf(%6d,i+1);printf();}printf(\n);for(i=9-weekday;i=days[month-1];i++,j++){if(j==7){j=0;printf(\n);}printf(%6d,i);}printf(\n------------------------------------------------\n);}//输入年份,打出12个月历,输入月份,打出该月的日历voidmonthDay(intyear){inti;charc;intmonth;for(i=0;i12;i++)yearMonth(year,i+1);printf(\n\n);printf(是否查看日历(y/n):);getchar();scanf(%c,&c);if(c=='y'){printf(请输入月份:);scanf(%d,&month);yearMonth(year,month);}elseexit(0);}//主菜单voidmenu(){printf(-----------------------------------------------\n);printf();printf(c语言课程设计-万年历\n\n);printf(***********************************************\n\n);printf(1、输入年份,判断是否为闰年\n);printf(2、输入年月日,判断该日为星期几\n);printf(3、输入年份,打出12个月历,输入月份,打出该月的日历\n\n);printf(***********************************************\n\n);}//判断是否继续voidisContinue(){charc;printf(是否继续(y/n):);getchar();scanf(%c,&c);if(c=='y')return;else{printf();exit(0);}}//主函数voidmain(){intnum;intyear;intmonth;intday;intweekday;while(1){system(CLS);//清屏menu();printf(请输入对应操作:);scanf(%d,&num);switch(num){case1:{printf(请输入年份:);scanf(%d,&year);if(isLeapYear(year))printf(%d年是闰年\n,year);elseprintf(%d年不是闰年\n);isContinue();break;}case2:{printf(请输入年月日,以空格隔开:);scanf(%d%d%d,&year,&month,&day);weekday=whichWeekday(year,month,day);printf(这天是星期%d\n,weekday);isContinue();break;}case3:{printf(请输入年份:);scanf(%d,&year);monthDay(year);isContinue();break;}default:{printf(您的输入有误);Sleep(1000);//延时一秒钟break;}}}}
本文标题:c语言课程设计简易万年历
链接地址:https://www.777doc.com/doc-6433374 .html