《万年历C源代码》由会员分享,可在线阅读,更多相关《万年历C源代码(7页珍藏版)》请在金锄头文库上搜索。
1、本文格式为Word版,下载可任意编辑万年历C源代码 #include iostream using namespace std; /#include stdafx.h/1900.1.1是星期1 int yeardaysform1900(int year); int mouthdays(int year,int mouth); void printyear(); void printmouth(int ,int); void findday(); char *dayss=日,一,二,三,四,五,六; int main() cout*endl; cout* 接待本万年历! *endl; cout*
2、endl; do cout李金香,请选择:endl; cout-1.显示莫一年的万年历 -endl; cout-2.显示莫一月的万年历 -endl; cout-3.查询莫一天的 -endl; cout-0.退出 -endl; int choice; cinchoice; hh:switch(choice) case 1:printyear();break; case 2: int year,mouth;cout请输入年和月,如:2022 10endl; cinyearmouth; printmouth(year,mouth);break; case 3:findday();break; cas
3、e 0:exit(0);break; default:cout输入错误,请重新输入:endl; cinchoice;goto hh; while(1); return 0; int yeardaysform1900(int year) int i,days=0; for(i=1990;iyear;i+) if(i%4=0i%100!=0|i%400=0) days+=366; else days+=365; return days; int mouthdays(int year,int mouth) int days; bool aa; if(year%4=0year%100!=0|year%
4、400=0)aa=true; else aa=false; switch(mouth) case 1:case 3:case 5:case 7:case 8:case 10:case 12: days=31;break; case 2:if(aa)days=29;else days=28;break; default:days=30; return days; void printyear() coutendl; cout请输入年:endl; coutendlendl; int year;int i; cinyear; for(i=1;i13;i+) printmouth(year,i);fo
5、r(int i=0;i100000000;i+); void printmouth(int year,int mouth) int i,days=0; coutendl; /int year,mouth; /cout请输入年和月,(如2022 3)endl; coutendl; /cinyearmouth; days+=yeardaysform1900(year); for(i=1;imouth;i+) days+=mouthdays(year,i); i=days%7; int j=0;int aa=0; coutyear年mouth月endl; for(j=0;j7;j+) coutday
6、ssj ;coutendl; for(j=0;ji+1;j+) cout ;aa+; if(aa%7=0)coutendl; for(j=1;j=mouthdays(year,mouth);j+) if(aa%7=0)coutendl; coutj ;aa+; coutendl; void findday()cout请输入年月日,如:2022 10 1endl; int year,mouth,day; cinyearmouthday;int totalday=0,i; for(i=1900;iyear;i+) totalday+=yeardaysform1900(i); for(i=1;imouth;i+) totalday+=mouthdays(year,i); for(i=1;iday;i+); totalday+=i; totalday%=7; coutyear年mouth月day日是星期daysstotaldayendl; 7