C语言万年历代码

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C语言万年历代码
万年历, C语言, 代码


#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;

char choose;

do

{printf ("\n\nplease input the year(0000~9999):\n\n");

scanf ("%d",&year);

if (year<0||year>9999) printf ("WANNING:ERROR,please input again!");}

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

printf ("\n\n");

do

{printf ("please input the month(0~12)\n\n\n");

scanf ("%d",&month);

if (month<=0||month>12) printf ("WANNING:ERROR,please input again!");}

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("would you like to continue(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");












自己做的日历(C语言)
本帖最后由 kekeyu 于 2010-8-15 16:59 编辑

一部分抄袭维他C /*Creat-by EvE*/

/*亿淫帝国地址:*/

/*C语言社区地址:*/

/*亿淫帝国QQ群:109559204*/



/*VC++6.0编译*/

#include "stdio.h"

#include "conio.h"

#include "stdlib.h"

int main()

{

void print_calendar(int year,int month); //打印日历

void first_set(int *year,int *month); //初始设定年月

int days_of_month(int year,int month)

; //某年某月一共多少天

int firstday_of_month(int year,int month); //某年某月第一天星期几

int year,month;

char ch;

first_set(&year,&month);

while(1)

{ print_calendar(year,month);

do{

ch=getch();

if(ch=='p'||ch=='P')

{ month-=1;

if(month<1) {month=12;year-=1;}

}

else if(ch=='n'||ch=='N')

{ month+=1;

if(month>12) {month=1;year+=1;}

}

else if(ch=='e'||ch=='E')

{ exit(0);

}

}while(ch!='n'&&ch!='N'&&ch!='p'&&ch!='P');

}

return 0;

}



void print_calendar(int year,int month)

{ int i,firstday=firstday_of_month(year,month);

int days=days_of_month(year,month);

system("cls");

printf("\t\t\t\t%d年%d月",year,month);

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

printf("\t\t\t 日 一 二 三 四 五 六\n");

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

for (i=0;i
printf ("%4c",' ');

for(i=firstday;i
{ if(i%7==0&&i!=0) printf("\n\t\t\t");

printf("%4d",i-firstday+1);

}

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

printf("\t\t********e退出 p上一月 n下一月********");

}



void first_set(int *year,int *month)

{ do{

printf ("please input the year(1~9999):");

scanf ("%d",year);

if(*year<1||*year>9999) printf ("WANNING:ERROR,please input again!\n");

}while (*year<1||*year>9999);

do{

printf ("please input the month(1~12):");

scanf ("%d",month);

if(*month<1||*month>12) printf ("WANNING:ERROR,please input again!\n");

}while (*month<1||*month>12);

}



int days_of_month(int year,int month)

{ int i;

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) i=31;

else if(month==4||month==6||month==9||month==11) i=30;

else if(month==2&&(year&&4==0&&year%100!=0||year%400==0)) i=29;

else i=28;

return i;

}



int firstday_of_month(int year,int month)

{ long z=(year-1)*365+1;

int i;

for (i=1;i
if ((i%4==0&&i%100!=0)||(i%400==0)) z++;

for(i=1;i
z+=days_of_month(year,i);

return z%7;

}
复制代码

收藏 分享 评分

相关文档
最新文档