联系方式企鹅1198736195
微Hearbeat021124
具体代码联系我发给你,你来定价
2条回答 默认 最新
关注 #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 leapyear(int year) //判断是否为闰年 { if(year%4==0&&year%100!=0||year%4==0&&year%400==0) { return(1); } else { return(0); } } 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 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); } int 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; } } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥20 统信uos升级apt后启动失败
- ¥15 求指导储层饱和度及含水率测井解释
- ¥200 建三维地震工区写入sgy到指定目录
- ¥30 靶向捕获测序探针设计自学
- ¥15 写代码写代码单片机代码写代码写数字按键代码
- ¥15 django按照距离进行排序
- ¥15 (标签-微信|关键词-微信公众号)
- ¥15 matlab中mjs用不了
- ¥15 Ios抖音直播的时候如何添加自定义图片在直播间!
- ¥60 riscv-pulpino总线上挂载axi从机