日历问题c语言,急求c大牛解决输出日历有关问题!

C/C++ code#include

#include

int isLeap(int year);

int GetMonthDays(int year,int month);

int GetWeekDay(int year,int month,int day);

void PrintMonthCalender(int year, int month);

int main()

{

int year,month;

printf("Please input year and month:");

scanf("%d %d",&year,&month);

printf("The result is:\n");

PrintMonthCalender(year,month);

return 0;

}

int isLeap(int year)

{

int m1,m2,m3;

m1=year%4;

m2=year%100;

m3=year%400;

if( (0==m1&&0!=m2) || (0==m3) )

{

return 1;

}

else

{

return 0;

}

}

int GetMonthDays(int year,int month)

{

int x=isLeap(year);

if(1 == x) //x代表判断闰年的返回值

{

switch(month)

{

case 1:case 3:case 5:case 7:case 8:case 10:case 12:

return 31;break;

case 4:case 6:case 9:case 11:

return 30;break;

case 2:

return 29;break;

default:printf("Your input is wrong.\n");exit(0);break;

}

}

else

{

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

return 31;

break;

case 4:

case 6:

case 9:

case 11:

return 30;break;

case 2:

return 28;

break;

default:printf("Your input is wrong.\n");

exit(0);

break;

}

}

return 0;

}

int GetWeekDay(int year,int month,int day)

{

int days,y,s=0,k,weekDay;

int x=isLeap(year);

if(1==x)

{

k=29;

}

if(0==x)

{

k=28;

}

y=year-1;

switch(month-1)

{

case 12:

s=s+31;

case 11:

s=s+30;

case 10:

s=s+31;

case 9:

s=s+30;

case 8:

s=s+31;

case 7:

s=s+31;

case 6:

s=s+30;

case 5:

s=s+31;

case 4:

s=s+30;

case 3:

s=s+31;

case 2:

s=s+k;

case 1:

s=s+31;

}

s=s+day;

days=y*365+y/400+y/4-y/100+s;

weekDay = days % 7;

return weekDay;

}

void PrintMonthCalender(int year,int month)

{

int startDay;

int i=1,count,t=1,w;

w=GetMonthDays(year,month);

startDay=GetWeekDay(year,month,1);

printf("\t\t\t%d-%d\n",year,month);

printf("Sun.\tMon.\tTue.\tWed.\tThu.\tFri.\tSat.\n");

count=startDay;

while( i <= w )

{

while(t < count )

{

printf("\t");

t++;

}

while(count<=7 && i <= w )

{

printf("%d\t",i);

i++;

count++;

}

printf("\n");

count=1;

}

printf("\n");

}

//有一些修改 自己看吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值