c语言万年历输出月历的思路,用C语言打印万年历.doc

#include

main()

{

void print_head(int x,int y); /*打印头文件*/

void print_month(int x,int y); /*打印月历*/

int days_of_month(int x,int y); /*计算指定年月的天数*/

int leap(int x,int y); /*计算指定年月1号是星期几*/

int i,days,year,month,firstday;

printf(" 本程序由winner(QQ:774686087)写于2011-9-23\n") ;

char choose;

do

{printf ("\n\n请输入年份(0000~9999):\n\n");

scanf ("%d",&year);

if (year<0||year>9999) printf ("警告:错误,请从新输入!");}

while (year<0||year>9999);

printf ("\n\n");

do

{printf ("请输入月份(0~12)\n\n\n");

scanf ("%d",&month);

if (month<=0||month>12) printf ("警告:错误,请再次输入!");}

while (month<=0||month>12);

printf ("\n\n");

days=days_of_month(year,month); /*调用函数*/

firstday=leap(year,month);

print_head(year,month);

print_month(firstday,days);

choose=getchar();

printf ("\n\n\n");

printf("继续吗?(y/n):\n\n");

scanf("%c",&choose);

if (choose=='y'||choose=='Y') main();

}

days_of_month(int x,int y)

{

int z;

switch (y)

{case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12: z=31;break;

case 4:

case 6:

case 9:

case 11: z=30;break;

case 2:

{if ((x%4==0&&x%100!=0)||(x%400==0)) z=29;

else z=28;break;

}

}

return z;

}

leap(int x,int y)

{

int z,i,moday;

z=(x+(x-1)/4-(x-1)/100+(x-1)/400)%7;

for (i=1;i

{moday=days_of_month(x,i); /*钳套调用函数*/

z=(z+moday)%7;

}

return z;

}

void print_head(int x,int y)

{

printf ("\n\n********************************************************************************\n\n");

printf ("\t\t\t\t%d %d\n\n",x,y);

printf ("\t\t\t SUN MON TUE WED THU FRI SAT\n");

printf ("\t\t\t");

}

void print_month(int x,int y)

{

int i;

char space[7]={' '};

for (i=1;i<=x;i++)

printf ("%4c",space[i]);

for (i=1;i<=y;i++)

{if ((i+x)%7==1) printf ("\n\t\t\t%4d",i);

else printf ("%4d",i);}

printf ("\n\n********************************************************************************\n\n

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值