(精!!!!c语言)多功能万年历

  • 格式:docx
  • 大小:14.33 KB
  • 文档页数:4

下载文档原格式

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

#include

#include

#include

void print_star()

{

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

}

void main()

{ system("COLOR b1");

void tools_1();

void tools_2();

char flag;

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

printf("\t\t\t\t**************欢迎使用万年历查询系统*************\n");

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

printf("Hi,user!下面是系统的一些功能:\n"); /*菜单*/

printf("1.查询任意一年的日历\n");

printf("2.查询任意一天是星期几\n");

print_star();

print_star();

printf("\n\nNow,your choice:");

scanf("%c",&flag);/*用户选择*/

switch(flag)

{case'1':tools_1();

case'2':tools_2();

}

}

void tools_1()/*功能一*/

{int year_month_day(int a),a,f;

void year(int ,int);

printf("请输入需要查看的年份(公元元年--.....):");

while(scanf("%d",&a)!='EOF')

{printf("********【%d】********\n",a);

f=year_month_day(a)%7+1;//计算所要查询年份的一月一号为星期几//

if(a==1)//初始化公元元年(公元元年为0001年,星期一)

f=1;

year(f,a);

printf("\n现在可继续查询.......若要退出请按....");

}

}

void year(int f,int a)//打印日历//

{

int s[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

char months[13][20]={" ","January","February","March","April","May","June","July","August","September","Octomber"," November","December"};

char weeks[7][10]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

int i,d,j,t=f;

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

{ printf("\n");

print_star();

printf("%40s\n",months[i]);

print_star();

for(d=0;d<7;d++)

printf("%-12s",weeks[d]);

printf("\n");

for(d=0;d

printf(" ");

t=d;

for(j=1;j<=s[i];j++)

{printf("%-12d",j);

t++;

if(t%7==0)

printf("\n");

}

if(((a%400==0)||(a%100!=0&&a%4==0))&&j==29)//如果是闰年,2月多打一天//

{printf("%-12d",j);

t++;}

if(t%7==0)

printf("\n");

t=t%7;

}

system("color a"); //闪光函数

Sleep(100);

system("color b");

Sleep(100);

system("color c");

Sleep(100);

system("color d");

Sleep(100);

system("color e");

Sleep(100);

system("color f");

Sleep(100);

system("color 0");

Sleep(100);

}

int year_month_day(int a)//计算从公元元年到所求年份之间的天数

{ int year_month_day_(int );

int d=0,f;

for(f=1;f

d+=year_month_day_(f);

return d;

}

int year_month_day_(int f)

{int m;

if(f%4!=0||(f%100==0&&f%400!=0))

m=365;

if(f%100==0&&f%400==0||(f%100!=0&&f%4==0))

m=366;

return(m);

}

void tools_2()//功能2(包括得到这一天星期几和该天的节日)

{ system("color c9");

int

i,s[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,0,31,29,31,30,31,30,31,31,30,31,30,31},f,a,c,d; char weeks[7][10]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"}; printf("请输入要查的年月日:");

while(scanf("%d,%d,%d",&a,&c,&d)!='EOF')

{

if((a%4!=0||(a%100==0&&a%400!=0))&&c==2&&d==29)

{printf("今年2月没有29号哦!请重新输入:\n");

continue;}

else

{

f=year_month_day(a)%7;

if(a==0)

f=0;

for(i=1;i

if(f%4!=0||(f%100==0&&f%400!=0))

f+=s[0][i];

else

f+=s[1][i];

f+=d;f%=7;

if(f==0)

printf("%d年%d月%d日是%s\n",a,c,d,weeks[6]);

else

printf("%d年%d月%d日是%s\n",a,c,d,weeks[f-1]);

if(c==1&&d==1)

printf("Good!亲,今天是元旦节\n");

相关主题