C语言课程设计—日历显示
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
char* month[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nev","Dec"};
char*
week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int j_leapyear(int year) //定义函数检测输入年份是否为闰年
{
if((/*year%400==0*/year%4==0&&year%100!=0)||(year%400==0))
return (1);
// else if(year%4==0&&year%100!=0)
// return (1);
else return 0;
}
int month_day(int year,int month) //检测该年月份有多少天
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(j_leapyear(year)&&month==2)
return 29;
else return (mon_day[month-1]);
}
int j_week(int year,int month,int day) //检测该天是星期几
{
int d=0,i; //d表示该天在该年份的累计天数
int w;
/* int month_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(j_leapyear(year)==1)
month_day[1]=29;
for(i=0;i d+=month_day[i]; d=d+day;*/ for(i=1;i d+=month_day(year,i); d+=day; w=(year-1)+(int)(year-1)/4-(int)(year-1)/100+(int)(year-1)/400+d;//网上公式 return ((int)w%7); } int allyear(int year) //输出全年日历 { int i,j,b; printf("\n%d 日历",year); for(i=1;i<=12;i++) { printf("\n\n\t%s\n",month[i-1]); // printf(" 7 1 2 3 4 5 6 \n"); printf(" S M T W T F S \n"); b=j_week(year,i,1); for(j=1;j<=month_day(year,i)+b;j++) { if(j<=b) printf(" "); else if(j-b<10) printf("%2d ",j-b); else printf("%2d ",j-b); //else printf("%2d ",j-b); if(j%7==0) putchar('\n'); } putchar('\n'); } return 0; } void month_print(int year,int month) //输入一个年月,输出这个月的日历 { int i,c,d; c=month_day(year,month); printf("\n\n %d年%d月日历\n",year,month); printf(" S M T W T F S \n"); d=j_week(year,month,1); for(i=1;i<=c+d;i++) { if(i<=d) printf(" "); else printf("%2d ",i-d); if(i%7==0) putchar('\n'); } putchar('\n'); } int jisuan_day(int year,int month,int day,int x,int y,int z) //输入年月日,输出距x年y月z 日有多少天,星期几,以及是否是公历节日 { int i,a,b,c=0,d=0,days=0,m=0,n=0,t; a=year>=x?year:x;