(完整版)C语言万年历
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C
说明部分
在TC或VC6.0中编译程序,编译成功后,通过命令行向编译生成的可执行文件(.exe)传递参数,在命令行中输入该执行文件的路径名称,然后再输入传入的参数,回车,就会显示出运行结果,效果如图1.1所示。
图1.1万年历运行界面
代码部分
#include <stdio.h>
main(int a,char **date)
}
if (day<0||day>month)
{
printf ("\n ERROR! the entered DAY is invalid\n");
exit (0);
}
week=(dy+dm+day-1+6)%7;
if(week<0)
week+=7;
if (day>0) /***判定查看类型***/
{
if (d==-1) year=year*10+(date[1][i]-'0');
if (d==0) month=month*10+(date[1][i]-'0');
if (d==1) day=day*10+(date[1][i]-'0');
i++;
}
if (month<1||month>12)/*若月份传入错误数字*/
else
d=(year-2000)/4-(year-2000)/100+(year-2000)/400;
dy=(year-2000)+d; /***该年1月1号到2000年1月1号的"星期差" ***/
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
}
else
{
week=++week%7;
printf ("\n the calender of this month as following\n");
printf ("\n *********************************\n");
printf (" SUN MON TUE WEN THU FRI STA\n");
switch (week)
{
case 0: strcpy (WEEK,"SUNDAY"); break;
case 1: strcpy (WEEK,"MONDAY"); break;
case 2: strcpy (WEEK,"TUESDAY"); break;
case 3: strcpy (WEEK,"WEDNESDAY"); break;
{
printf ("\n ERROR! the entered MONTH is invalid\n");
exit (0);
}
if (year==2000)
{
dy=0;/*年引起的星期差为0个*/
m2=1;/*2月引起的星期差为1个*/
goto la_100;
}
if (year>2000)
d=(year-1-2000)/4-(year-1-2000)/100+(year-1-2000)/400+1;
while (date[1][i])/*遍历传入的参数日期,计算出year,month,day*/
{
if ((date[1][i]=='/'||date[1][i]=='.')&&d==-1) { d=0; i++; continue; }
if ((date[1][i]=='/'||date[1][i]=='.')&&d==0) { d=1; i++; continue; }
for (i=0;i<week;i++)
printf (" ");
for (i=1;i<=month;i++)
{
printf (" %2d ",i);
week++;
if (week%7==0&&i!=month)
printf ("\n");
}
printf ("\n *********************************\n");
case 3: dm=3+m2; month=31; break;
case 4: dm=6+m2; month=30; break;
case 5: : dm=4+m2; month=30; break;
case 7: dm=6+m2; month=31; break;
case 4: strcpy (WEEK,"THURSDAY"); break;
case 5: strcpy (WEEK,"FRIDAY"); break;
case 6: strcpy (WEEK,"SATURDAY"); break;
}
printf ("\n this day is %s \( %d \)\n\n OK!\n",WEEK,week);
{
int year=,month=0,day=0,week;
int d,i,dm,dy,m2;
char WEEK[9];
if (a==1)
{
printf ("\n ERROR! you forgot to enter the date you want to view\n");
exit (0);
}
i=0; d=-1;
case 8: dm=2+m2; month=31; break;
case 9: dm=5+m2; month=30; break;
case 10: dm=m2; month=31; break;
case 11: dm=3+m2; month=30; break;
case 12: dm=5+m2; month=31; break;
printf ("\n OK!\n");
}
}
m2=1;
else
m2=0; /***该年是否润***/
la_100: /**** la_100 ****/
/***该月以前的月所引起的"星期差" ***/
switch (month)
{
case 1: dm=0; month=31; break; /*** month在此存放该月天数***/
case 2: dm=3; month=d==1? 29:28; break;
说明部分
在TC或VC6.0中编译程序,编译成功后,通过命令行向编译生成的可执行文件(.exe)传递参数,在命令行中输入该执行文件的路径名称,然后再输入传入的参数,回车,就会显示出运行结果,效果如图1.1所示。
图1.1万年历运行界面
代码部分
#include <stdio.h>
main(int a,char **date)
}
if (day<0||day>month)
{
printf ("\n ERROR! the entered DAY is invalid\n");
exit (0);
}
week=(dy+dm+day-1+6)%7;
if(week<0)
week+=7;
if (day>0) /***判定查看类型***/
{
if (d==-1) year=year*10+(date[1][i]-'0');
if (d==0) month=month*10+(date[1][i]-'0');
if (d==1) day=day*10+(date[1][i]-'0');
i++;
}
if (month<1||month>12)/*若月份传入错误数字*/
else
d=(year-2000)/4-(year-2000)/100+(year-2000)/400;
dy=(year-2000)+d; /***该年1月1号到2000年1月1号的"星期差" ***/
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
}
else
{
week=++week%7;
printf ("\n the calender of this month as following\n");
printf ("\n *********************************\n");
printf (" SUN MON TUE WEN THU FRI STA\n");
switch (week)
{
case 0: strcpy (WEEK,"SUNDAY"); break;
case 1: strcpy (WEEK,"MONDAY"); break;
case 2: strcpy (WEEK,"TUESDAY"); break;
case 3: strcpy (WEEK,"WEDNESDAY"); break;
{
printf ("\n ERROR! the entered MONTH is invalid\n");
exit (0);
}
if (year==2000)
{
dy=0;/*年引起的星期差为0个*/
m2=1;/*2月引起的星期差为1个*/
goto la_100;
}
if (year>2000)
d=(year-1-2000)/4-(year-1-2000)/100+(year-1-2000)/400+1;
while (date[1][i])/*遍历传入的参数日期,计算出year,month,day*/
{
if ((date[1][i]=='/'||date[1][i]=='.')&&d==-1) { d=0; i++; continue; }
if ((date[1][i]=='/'||date[1][i]=='.')&&d==0) { d=1; i++; continue; }
for (i=0;i<week;i++)
printf (" ");
for (i=1;i<=month;i++)
{
printf (" %2d ",i);
week++;
if (week%7==0&&i!=month)
printf ("\n");
}
printf ("\n *********************************\n");
case 3: dm=3+m2; month=31; break;
case 4: dm=6+m2; month=30; break;
case 5: : dm=4+m2; month=30; break;
case 7: dm=6+m2; month=31; break;
case 4: strcpy (WEEK,"THURSDAY"); break;
case 5: strcpy (WEEK,"FRIDAY"); break;
case 6: strcpy (WEEK,"SATURDAY"); break;
}
printf ("\n this day is %s \( %d \)\n\n OK!\n",WEEK,week);
{
int year=,month=0,day=0,week;
int d,i,dm,dy,m2;
char WEEK[9];
if (a==1)
{
printf ("\n ERROR! you forgot to enter the date you want to view\n");
exit (0);
}
i=0; d=-1;
case 8: dm=2+m2; month=31; break;
case 9: dm=5+m2; month=30; break;
case 10: dm=m2; month=31; break;
case 11: dm=3+m2; month=30; break;
case 12: dm=5+m2; month=31; break;
printf ("\n OK!\n");
}
}
m2=1;
else
m2=0; /***该年是否润***/
la_100: /**** la_100 ****/
/***该月以前的月所引起的"星期差" ***/
switch (month)
{
case 1: dm=0; month=31; break; /*** month在此存放该月天数***/
case 2: dm=3; month=d==1? 29:28; break;