输入任意一个年份的值,输出该年份的日历。要求将12个月自上而下排成一列。

编译C语言程序... 编译C语言程序 展开
 我来答
叮当猫武汉
2010-05-07 · TA获得超过3739个赞
知道大有可为答主
回答量:744
采纳率:0%
帮助的人:0
展开全部
#include <stdio.h>
#include <string.h>
#include <ctype.h>
long year;
int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void inputyear(){
printf("Please input the year:\n");
scanf("%d",&year);
if(!(year%4)&&(year%100)||!(year%400))
monthdays[1]=29;
else
monthdays[1]=28;
}
void printCala(){
int countyear,countday=0,weekflag,i,j,k,c;
int startmon,endmon,year1;
year1=year-1;
countyear=(year1-year1%4)/4-(year1-year1%100)/100+(year1-year1%400)/400;

weekflag=(countyear*366+(year-1-countyear)*365+1)%7-1;
startmon=1;
endmon=12;
for(k=1;k<startmon;k++)
weekflag=(weekflag+monthdays[k-1])%7;
for(k=startmon;k<=endmon;k++)
{
printf("\n %ld year ",year);
switch(k)
{
case 1: printf("January\n");break;
case 2: printf("February\n");break;
case 3: printf("March\n");break;
case 4: printf("April\n");break;
case 5: printf("May\n");break;
case 6: printf("June\n");break;
case 7: printf("July\n");break;
case 8: printf("August\n");break;
case 9: printf("September\n");break;
case 10: printf("October\n");break;
case 11: printf("November\n");break;
case 12: printf("December\n");break;
}
printf("___________________________\n");
printf("Sun Mon Tue Whe Thr Fri Sat\n");
if(weekflag!=0)
for(countday=0,j=0;j<weekflag;j++)
{printf(" ");
countday++;}
for(i=1;i<=monthdays[k-1];i++)
{if(countday>0&&countday%7==0)
printf("\n");
printf("%3d ",i);
countday++;}
weekflag=(weekflag+monthdays[k-1])%7;
printf("\n___________________________\n");
}
}
int main()
{
inputyear();
printCala();
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式