万年历C语言代码

2022-07-14 03:11:11   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《万年历C语言代码》,欢迎阅读!
万年历,语言,代码

万年历C语言代码 #include

main() { for(;;) {

int year,month,a,b,c,m,n=28;/*定义变量*/ long e;

printf("请输入年份"); scanf("%d",&year); e=year;

e--; /*前一年*/

e=(e*365+e/4)%7; /*计算这一年的第一天是星期几*/ m=e; /*把第一天的日期赋给m*/ if((year%4==0)||(year%100!=0)&&(year%400!=0))/*如果是闰年*/ n++;

printf("%d的日历:",year);

for(month=1;month<=12;month++) {

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)/*这几个月每个月都是31*/ { c=0;

printf("\n");

printf(" %d \n",month);

printf(" \n");

for(b=1;b<=m;b++) { c++;

printf(" ");/*从星期日开始到这个月开始的那天前都是空的*/ }

for(a=1;a<=31;a++) { c++;

if(c%7-1==0&&c!=1)/*判断一行是否已排满,满了就要换行*/ printf("\n");

if(a<10) /*如果是小于10,空一格,大于10,前后空*/ printf(" ");

printf(" %d ",a); m++;

if(m==7)/*一行排满,开始换行。(指的是这个月的最后一行)*/ m=0;


}

printf("\n"); } else {

if(month==4||month==6||month==9||month==11||month==2) {

if(month==2)/*判断2月份*/ { c=0; printf("\n"); printf(" %d \n",month); printf(" "); printf(" \n"); for(b=1;b<=m;b++) { c++; printf(" "); }

for(a=1;a<=n;a++) { c++; if(c%7-1==0&&c!=1) printf("\n"); if(a<10) printf(" "); printf(" %d ",a); m++; if(m==7) m=0; }

printf("\n"); } else { c=0; printf("\n"); printf(" %d \n",month); printf(" \n"); for(b=1;b<=m;b++) { c++; printf(" "); }


}

} } } }

for(a=1;a<=30;a++) { c++; if(c%7-1==0&&c!=1) printf("\n"); if(a<10) printf(" "); printf(" %d ",a); m++; if(m==7) m=0; }

printf("\n");}


本文来源:https://www.dywdw.cn/3d1649c2d5bbfd0a795673d7.html

相关推荐
推荐阅读